Lines Matching refs:cls

260     def __class_getitem__(cls, type):
271 # When cls._FIELDS is filled in with a list of Field objects, the name
470 # (cls.fieldname=defaultvalue). But that won't work for a
599 def _frozen_get_del_attr(cls, fields, globals):
600 locals = {'cls': cls,
609 (f'if type(self) is cls or name in {fields_str}:',
611 f'super(cls, self).__setattr__(name, value)'),
616 (f'if type(self) is cls or name in {fields_str}:',
618 f'super(cls, self).__delattr__(name)'),
664 def _is_type(annotation, cls, a_module, a_type, is_type_predicate):
675 # - cls is the class that this annotation was found in
712 ns = sys.modules.get(cls.__module__).__dict__
715 module = sys.modules.get(cls.__module__)
723 def _get_field(cls, a_name, a_type, default_kw_only):
731 default = getattr(cls, a_name, MISSING)
761 # typing has been imported by any module (not necessarily cls's
767 and _is_type(f.type, cls, typing, typing.ClassVar,
779 and _is_type(f.type, cls, dataclasses, dataclasses.InitVar,
820 def _set_qualname(cls, value):
824 value.__qualname__ = f"{cls.__qualname__}.{value.__name__}"
827 def _set_new_attribute(cls, name, value):
830 if name in cls.__dict__:
832 _set_qualname(cls, value)
833 setattr(cls, name, value)
842 def _hash_set_none(cls, fields, globals):
845 def _hash_add(cls, fields, globals):
847 return _set_qualname(cls, _hash_fn(flds, globals))
849 def _hash_exception(cls, fields, globals):
852 f'in class {cls.__name__}')
884 def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
892 if cls.__module__ in sys.modules:
893 globals = sys.modules[cls.__module__].__dict__
896 # a custom string to cls.__module__. In which case
902 setattr(cls, _PARAMS, _DataclassParams(init, repr, eq, order,
911 for b in cls.__mro__[-1:0:-1]:
934 cls_annotations = cls.__dict__.get('__annotations__', {})
947 and _is_type(type, cls, dataclasses, dataclasses.KW_ONLY,
958 cls_fields.append(_get_field(cls, name, type, kw_only))
967 if isinstance(getattr(cls, f.name, None), Field):
975 delattr(cls, f.name)
977 setattr(cls, f.name, f.default)
980 for name, value in cls.__dict__.items():
998 setattr(cls, _FIELDS, fields)
1005 class_hash = cls.__dict__.get('__hash__', MISSING)
1007 (class_hash is None and '__eq__' in cls.__dict__))
1024 has_post_init = hasattr(cls, _POST_INIT_NAME)
1026 _set_new_attribute(cls, '__init__',
1047 _set_new_attribute(cls, '__repr__', _repr_fn(flds, globals))
1055 _set_new_attribute(cls, '__eq__',
1070 if _set_new_attribute(cls, name,
1074 f'in class {cls.__name__}. Consider using '
1078 for fn in _frozen_get_del_attr(cls, field_list, globals):
1079 if _set_new_attribute(cls, fn.__name__, fn):
1081 f'in class {cls.__name__}')
1091 cls.__hash__ = hash_action(cls, field_list, globals)
1093 if not getattr(cls, '__doc__'):
1098 text_sig = str(inspect.signature(cls)).replace(' -> None', '')
1101 cls.__doc__ = (cls.__name__ + text_sig)
1105 _set_new_attribute(cls, '__match_args__',
1112 cls = _add_slots(cls, frozen, weakref_slot)
1114 abc.update_abstractmethods(cls)
1116 return cls
1133 def _get_slots(cls):
1134 match cls.__dict__.get('__slots__'):
1144 raise TypeError(f"Slots of '{cls.__name__}' cannot be determined")
1147 def _add_slots(cls, is_frozen, weakref_slot):
1152 if '__slots__' in cls.__dict__:
1153 raise TypeError(f'{cls.__name__} already specifies __slots__')
1156 cls_dict = dict(cls.__dict__)
1157 field_names = tuple(f.name for f in fields(cls))
1160 itertools.chain.from_iterable(map(_get_slots, cls.__mro__[1:-1]))
1187 qualname = getattr(cls, '__qualname__', None)
1188 cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
1190 cls.__qualname__ = qualname
1195 cls.__getstate__ = _dataclass_getstate
1197 cls.__setstate__ = _dataclass_setstate
1199 return cls
1202 def dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False,
1219 def wrap(cls):
1220 return _process_class(cls, init, repr, eq, order, unsafe_hash,
1225 if cls is None:
1230 return wrap(cls)
1259 cls = obj if isinstance(obj, type) else type(obj)
1260 return hasattr(cls, _FIELDS)
1444 cls = types.new_class(cls_name, bases, {}, exec_body_callback)
1447 return dataclass(cls, init=init, repr=repr, eq=eq, order=order,