MCPcopy Index your code
hub / github.com/python/cpython / field

Function field

Lib/dataclasses.py:391–412  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

389# so that a type checker can be told (via overloads) that this is a
390# function whose type depends on its parameters.
391def 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
415def _fields_in_init_order(fields):

Callers 15

ThemeClass · 0.90
TreeNodeClass · 0.90
ThreadDataClass · 0.90
CreatureDataMixinClass · 0.90
WithPostInitClass · 0.90
ReaderClass · 0.90
RefreshCacheClass · 0.90
CompletingReaderClass · 0.90
ConsoleClass · 0.90
ReadlineConfigClass · 0.90
_ReadlineWrapperClass · 0.90
ExceptHookHandlerClass · 0.90

Calls 1

FieldClass · 0.70

Tested by 8

test_field_reprMethod · 0.68
test_simpleMethod · 0.68
test_class_varMethod · 0.68
test_other_paramsMethod · 0.68
test_make_dataclassMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…