PyDocs

Nav

Python Runtime Services

astuple

dataclasses

function (source)
  • astuple(obj, *, tuple_factory=tuple)
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 function applies recursively to field values that are
dataclass instances. This will also look into built-in containers:
tuples, lists, dicts, and frozendicts. Other objects are copied
with 'copy.deepcopy()'.
0 Examples
No examples for dataclasses/astuple.
See Also
No see-alsos for dataclasses/astuple
0 Notes
No notes for astuple