Return a tuple describing the fields of this dataclass. Accepts a dataclass or an instance of one. Tuple elements are of type Field.
(class_or_instance)
| 1233 | |
| 1234 | |
| 1235 | def fields(class_or_instance): |
| 1236 | """Return a tuple describing the fields of this dataclass. |
| 1237 | |
| 1238 | Accepts a dataclass or an instance of one. Tuple elements are of |
| 1239 | type Field. |
| 1240 | """ |
| 1241 | |
| 1242 | # Might it be worth caching this, per class? |
| 1243 | try: |
| 1244 | fields = getattr(class_or_instance, _FIELDS) |
| 1245 | except AttributeError: |
| 1246 | raise TypeError('must be called with a dataclass type or instance') from None |
| 1247 | |
| 1248 | # Exclude pseudo-fields. Note that fields is sorted by insertion |
| 1249 | # order, so the order of the tuple is as the fields were defined. |
| 1250 | return tuple(f for f in fields.values() if f._field_type is _FIELD) |
| 1251 | |
| 1252 | |
| 1253 | def _is_dataclass_instance(obj): |
no test coverage detected