You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
881 B
28 lines
881 B
from dataclasses import dataclass
|
|
from typing import Union
|
|
|
|
|
|
# def dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False,
|
|
# unsafe_hash=False, frozen=False):
|
|
# """Returns the same class as was passed in, with dunder methods
|
|
# added 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. If unsafe_hash is true, a
|
|
# __hash__() method function is added. If frozen is true, fields may
|
|
# not be assigned to after instance creation.
|
|
# """
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class A:
|
|
a: int
|
|
b: bool
|
|
c: str = "asd"
|
|
f: Union[int, bool, str] = 0
|
|
|
|
def foo(self):
|
|
print(self)
|
|
|