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

Function dataclass

Lib/dataclasses.py:1414–1442  ·  view source on GitHub ↗

Add dunder methods based on the fields defined in the class. Examines PEP 526 __annotations__ to determine fields. If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added.

(cls=None, /, *, init=True, repr=True, eq=True, order=False,
              unsafe_hash=False, frozen=False, match_args=True,
              kw_only=False, slots=False, weakref_slot=False)

Source from the content-addressed store, hash-verified

1412
1413
1414def dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False,
1415 unsafe_hash=False, frozen=False, match_args=True,
1416 kw_only=False, slots=False, weakref_slot=False):
1417 """Add dunder methods based on the fields defined in the class.
1418
1419 Examines PEP 526 __annotations__ to determine fields.
1420
1421 If init is true, an __init__() method is added to the class. If repr
1422 is true, a __repr__() method is added. If order is true, rich
1423 comparison dunder methods are added. If unsafe_hash is true, a
1424 __hash__() method is added. If frozen is true, fields may not be
1425 assigned to after instance creation. If match_args is true, the
1426 __match_args__ tuple is added. If kw_only is true, then by default
1427 all fields are keyword-only. If slots is true, a new class with a
1428 __slots__ attribute is returned.
1429 """
1430
1431 def wrap(cls):
1432 return _process_class(cls, init, repr, eq, order, unsafe_hash,
1433 frozen, match_args, kw_only, slots,
1434 weakref_slot)
1435
1436 # See if we're being called as @dataclass or @dataclass().
1437 if cls is None:
1438 # We're called with parens.
1439 return wrap
1440
1441 # We're called as @dataclass without parens.
1442 return wrap(cls)
1443
1444
1445def fields(class_or_instance):

Calls 1

wrapFunction · 0.70