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)
| 1444 | |
| 1445 | |
| 1446 | def fields(class_or_instance): |
| 1447 | """Return a tuple describing the fields of this dataclass. |
| 1448 | |
| 1449 | Accepts a dataclass or an instance of one. Tuple elements are of |
| 1450 | type Field. |
| 1451 | """ |
| 1452 | |
| 1453 | # Might it be worth caching this, per class? |
| 1454 | try: |
| 1455 | fields = getattr(class_or_instance, _FIELDS) |
| 1456 | except AttributeError: |
| 1457 | raise TypeError('must be called with a dataclass type or instance') from None |
| 1458 | |
| 1459 | # Exclude pseudo-fields. Note that fields is sorted by insertion |
| 1460 | # order, so the order of the tuple is as the fields were defined. |
| 1461 | return tuple(f for f in fields.values() if f._field_type is _FIELD) |
| 1462 | |
| 1463 | |
| 1464 | def _is_dataclass_instance(obj): |
searching dependent graphs…