Lines Matching defs:fields
24 'fields',
169 # tuple of __init__ parameter names; non-init fields must be matched by keyword.
189 # A sentinel object to indicate that following fields are keyword-only by
196 # read-only proxy that can be shared among all fields.
199 # Markers for the various kinds of fields and pseudo-fields.
272 # and type fields will have been populated.
370 """Return an object to identify dataclass fields.
392 def _fields_in_init_order(fields):
393 # Returns the fields as __init__ will output them. It returns 2 tuples:
396 return (tuple(f for f in fields if f.init and not f.kw_only),
397 tuple(f for f in fields if f.init and f.kw_only)
401 def _tuple_str(obj_name, fields):
403 # member. So, if fields is ['x', 'y'] and obj_name is "self",
407 if not fields:
410 return f'({",".join([f"{obj_name}.{f.name}" for f in fields])},)'
438 # If we're a frozen class, then assign to our fields in __init__
528 def _init_fn(fields, std_fields, kw_only_fields, frozen, has_post_init,
530 # fields contains both real fields and InitVar pseudo-fields.
532 # Make sure we don't have fields without defaults following fields
540 # Only consider the non-kw-only fields in the __init__ call.
548 locals = {f'_type_{f.name}': f.type for f in fields}
556 for f in fields:
565 params_str = ','.join(f.name for f in fields
588 def _repr_fn(fields, globals):
593 for f in fields]) +
599 def _frozen_get_del_attr(cls, fields, globals):
602 if fields:
603 fields_str = '(' + ','.join(repr(f.name) for f in fields) + ',)'
625 # Create a comparison function. If the fields in the object are
638 def _hash_fn(fields, globals):
639 self_tuple = _tuple_str('self', fields)
783 # Validations for individual fields. This is delayed until now,
800 # For real and InitVar fields, if kw_only wasn't specified use the
811 # For real fields, disallow mutable defaults. Use unhashable as a proxy
842 def _hash_set_none(cls, fields, globals):
845 def _hash_add(cls, fields, globals):
846 flds = [f for f in fields if (f.compare if f.hash is None else f.hash)]
849 def _hash_exception(cls, fields, globals):
888 # derived class fields overwrite base class fields, but the order
890 fields = {}
918 fields[f.name] = f
924 # adds no new annotations. We use this to compute fields that are
931 # actual default value. Pseudo-fields ClassVars and InitVars are
932 # included, despite the fact that they're not real fields. That's
936 # Now find fields in our class. While doing so, validate some
961 fields[f.name] = f
996 # Remember all of the fields on our class (including bases). This
998 setattr(cls, _FIELDS, fields)
1014 # Include InitVars and regular fields (so, not ClassVars). This is
1017 all_init_fields = [f for f in fields.values()
1035 '__dataclass_self__' if 'self' in fields
1041 # Get the fields as a list, and include only real fields. This is
1043 field_list = [f for f in fields.values() if f._field_type is _FIELD]
1121 # the code instead of iterating over fields. But that can be a project for
1124 return [getattr(self, f.name) for f in fields(self)]
1128 for field, value in zip(fields(self), state):
1157 field_names = tuple(f.name for f in fields(cls))
1205 """Add dunder methods based on the fields defined in the class.
1207 Examines PEP 526 __annotations__ to determine fields.
1212 __hash__() method is added. If frozen is true, fields may not be
1215 all fields are keyword-only. If slots is true, a new class with a
1233 def fields(class_or_instance):
1234 """Return a tuple describing the fields of this dataclass.
1242 fields = getattr(class_or_instance, _FIELDS)
1246 # Exclude pseudo-fields. Note that fields is sorted by insertion
1247 # order, so the order of the tuple is as the fields were defined.
1248 return tuple(f for f in fields.values() if f._field_type is _FIELD)
1264 """Return the fields of a dataclass instance as a new dictionary mapping
1290 for f in fields(obj):
1304 # - it does not recurse in to the namedtuple fields and
1329 """Return the fields of a dataclass instance as a new tuple of field values.
1355 for f in fields(obj):
1379 def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
1385 The dataclass name will be 'cls_name'. 'fields' is an iterable
1414 for item in fields:
1454 """Return a new object replacing specified fields with new values.
1474 # It's an error to have init=False fields in 'changes'.
1478 # Only consider normal fields or InitVars.
1497 # __post_init__() (if defined), using all of the init fields we've
1499 # changes that aren't fields, this will correctly raise a