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

Function astuple

Lib/dataclasses.py:1568–1589  ·  view source on GitHub ↗

Return the fields of a dataclass instance as a new tuple of field values. Example usage:: @dataclass class C: x: int y: int c = C(1, 2) assert astuple(c) == (1, 2) If given, 'tuple_factory' will be used instead of built-in tuple. The functi

(obj, *, tuple_factory=tuple)

Source from the content-addressed store, hash-verified

1566
1567
1568def astuple(obj, *, tuple_factory=tuple):
1569 """Return the fields of a dataclass instance as a new tuple of field values.
1570
1571 Example usage::
1572
1573 @dataclass
1574 class C:
1575 x: int
1576 y: int
1577
1578 c = C(1, 2)
1579 assert astuple(c) == (1, 2)
1580
1581 If given, 'tuple_factory' will be used instead of built-in tuple.
1582 The function applies recursively to field values that are
1583 dataclass instances. This will also look into built-in containers:
1584 tuples, lists, and dicts. Other objects are copied with 'copy.deepcopy()'.
1585 """
1586
1587 if not _is_dataclass_instance(obj):
1588 raise TypeError("astuple() should be called on dataclass instances")
1589 return _astuple_inner(obj, tuple_factory)
1590
1591
1592def _astuple_inner(obj, tuple_factory):

Calls 2

_is_dataclass_instanceFunction · 0.85
_astuple_innerFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…