MCPcopy
hub / github.com/python-attrs/attrs / __init__

Method __init__

src/attr/_make.py:674–773  ·  view source on GitHub ↗
(
        self,
        cls: type,
        these,
        auto_attribs: bool,
        props: ClassProps,
        has_custom_setattr: bool,
    )

Source from the content-addressed store, hash-verified

672 )
673
674 def __init__(
675 self,
676 cls: type,
677 these,
678 auto_attribs: bool,
679 props: ClassProps,
680 has_custom_setattr: bool,
681 ):
682 attrs, base_attrs, base_map = _transform_attrs(
683 cls,
684 these,
685 auto_attribs,
686 props.kw_only,
687 props.collected_fields_by_mro,
688 props.field_transformer,
689 )
690
691 self._cls = cls
692 self._cls_dict = dict(cls.__dict__) if props.is_slotted else {}
693 self._attrs = attrs
694 self._base_names = {a.name for a in base_attrs}
695 self._base_attr_map = base_map
696 self._attr_names = tuple(a.name for a in attrs)
697 self._slots = props.is_slotted
698 self._frozen = props.is_frozen
699 self._weakref_slot = props.has_weakref_slot
700 self._cache_hash = (
701 props.hashability is ClassProps.Hashability.HASHABLE_CACHED
702 )
703 self._has_pre_init = bool(getattr(cls, "__attrs_pre_init__", False))
704 self._pre_init_has_args = False
705 if self._has_pre_init:
706 # Check if the pre init method has more arguments than just `self`
707 # We want to pass arguments if pre init expects arguments
708 pre_init_func = cls.__attrs_pre_init__
709 pre_init_signature = inspect.signature(pre_init_func)
710 self._pre_init_has_args = len(pre_init_signature.parameters) > 1
711 self._has_post_init = bool(getattr(cls, "__attrs_post_init__", False))
712 self._delete_attribs = not bool(these)
713 self._is_exc = props.is_exception
714 self._on_setattr = props.on_setattr_hook
715
716 self._has_custom_setattr = has_custom_setattr
717 self._wrote_own_setattr = False
718
719 self._cls_dict["__attrs_attrs__"] = self._attrs
720 self._cls_dict["__attrs_props__"] = props
721
722 if props.is_frozen:
723 self._cls_dict["__setattr__"] = _frozen_setattrs
724 self._cls_dict["__delattr__"] = _frozen_delattrs
725
726 self._wrote_own_setattr = True
727 elif self._on_setattr in (
728 _DEFAULT_ON_SETATTR,
729 setters.validate,
730 setters.convert,
731 ):

Callers

nothing calls this directly

Calls 2

_transform_attrsFunction · 0.85

Tested by

no test coverage detected