Return an object to identify dataclass fields. default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If init is true, the field will be a parameter to the class's __init__() function. If repr is true, the field w
(*, default=MISSING, default_factory=MISSING, init=True, repr=True,
hash=None, compare=True, metadata=None, kw_only=MISSING, doc=None)
| 389 | # so that a type checker can be told (via overloads) that this is a |
| 390 | # function whose type depends on its parameters. |
| 391 | def field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, |
| 392 | hash=None, compare=True, metadata=None, kw_only=MISSING, doc=None): |
| 393 | """Return an object to identify dataclass fields. |
| 394 | |
| 395 | default is the default value of the field. default_factory is a |
| 396 | 0-argument function called to initialize a field's value. If init |
| 397 | is true, the field will be a parameter to the class's __init__() |
| 398 | function. If repr is true, the field will be included in the |
| 399 | object's repr(). If hash is true, the field will be included in the |
| 400 | object's hash(). If compare is true, the field will be used in |
| 401 | comparison functions. metadata, if specified, must be a mapping |
| 402 | which is stored but not otherwise examined by dataclass. If kw_only |
| 403 | is true, the field will become a keyword-only parameter to |
| 404 | __init__(). doc is an optional docstring for this field. |
| 405 | |
| 406 | It is an error to specify both default and default_factory. |
| 407 | """ |
| 408 | |
| 409 | if default is not MISSING and default_factory is not MISSING: |
| 410 | raise ValueError('cannot specify both default and default_factory') |
| 411 | return Field(default, default_factory, init, repr, hash, compare, |
| 412 | metadata, kw_only, doc) |
| 413 | |
| 414 | |
| 415 | def _fields_in_init_order(fields): |
searching dependent graphs…