MCPcopy Index your code
hub / github.com/python/mypy / _propertize_callables

Method _propertize_callables

mypy/plugins/dataclasses.py:777–795  ·  view source on GitHub ↗

Converts all attributes with callable types to @property methods. This avoids the typechecker getting confused and thinking that `my_dataclass_instance.callable_attr(foo)` is going to receive a `self` argument (it is not).

(
        self, attributes: list[DataclassAttribute], settable: bool = True
    )

Source from the content-addressed store, hash-verified

775 info.names[var.name] = SymbolTableNode(MDEF, var)
776
777 def _propertize_callables(
778 self, attributes: list[DataclassAttribute], settable: bool = True
779 ) -> None:
780 """Converts all attributes with callable types to @property methods.
781
782 This avoids the typechecker getting confused and thinking that
783 `my_dataclass_instance.callable_attr(foo)` is going to receive a
784 `self` argument (it is not).
785
786 """
787 info = self._cls.info
788 for attr in attributes:
789 if isinstance(get_proper_type(attr.type), CallableType):
790 var = attr.to_var(info)
791 var.info = info
792 var.is_property = True
793 var.is_settable_property = settable
794 var._fullname = info.fullname + "." + var.name
795 info.names[var.name] = SymbolTableNode(MDEF, var)
796
797 def _is_kw_only_type(self, node: Type | None) -> bool:
798 """Checks if the type of the node is the KW_ONLY sentinel value."""

Callers 1

transformMethod · 0.95

Calls 4

get_proper_typeFunction · 0.90
SymbolTableNodeClass · 0.90
isinstanceFunction · 0.85
to_varMethod · 0.80

Tested by

no test coverage detected