MCPcopy Index your code
hub / github.com/python/cpython / fields

Function fields

Lib/dataclasses.py:1446–1461  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1444
1445
1446def 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
1464def _is_dataclass_instance(obj):

Callers 15

create_autospecFunction · 0.90
suspendMethod · 0.90
_dataclass_getstateFunction · 0.85
_dataclass_setstateFunction · 0.85
_add_slotsFunction · 0.85
_asdict_innerFunction · 0.85
_astuple_innerFunction · 0.85
test_no_fieldsMethod · 0.85
test_class_markerMethod · 0.85
test_field_orderMethod · 0.85
test_class_varMethod · 0.85

Calls 1

valuesMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…