MCPcopy Index your code
hub / github.com/RustPython/RustPython / astuple

Function astuple

Lib/dataclasses.py:1567–1588  ·  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

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

Calls 2

_is_dataclass_instanceFunction · 0.85
_astuple_innerFunction · 0.85