This method iterates over all fields that are defined and yields ``(key, value)`` tuples. Per default all fields are returned, but it's possible to limit that to some fields by providing the `only` parameter or to exclude some using the `exclude` parameter. Both sho
(
self,
exclude: t.Optional[t.Container[str]] = None,
only: t.Optional[t.Container[str]] = None,
)
| 143 | raise TypeError(f"unknown attribute {next(iter(attributes))!r}") |
| 144 | |
| 145 | def iter_fields( |
| 146 | self, |
| 147 | exclude: t.Optional[t.Container[str]] = None, |
| 148 | only: t.Optional[t.Container[str]] = None, |
| 149 | ) -> t.Iterator[t.Tuple[str, t.Any]]: |
| 150 | """This method iterates over all fields that are defined and yields |
| 151 | ``(key, value)`` tuples. Per default all fields are returned, but |
| 152 | it's possible to limit that to some fields by providing the `only` |
| 153 | parameter or to exclude some using the `exclude` parameter. Both |
| 154 | should be sets or tuples of field names. |
| 155 | """ |
| 156 | for name in self.fields: |
| 157 | if ( |
| 158 | (exclude is None and only is None) |
| 159 | or (exclude is not None and name not in exclude) |
| 160 | or (only is not None and name in only) |
| 161 | ): |
| 162 | try: |
| 163 | yield name, getattr(self, name) |
| 164 | except AttributeError: |
| 165 | pass |
| 166 | |
| 167 | def iter_child_nodes( |
| 168 | self, |
no outgoing calls
no test coverage detected