MCPcopy Create free account
hub / github.com/python/mypy / _make_frozen

Function _make_frozen

mypy/plugins/attrs.py:851–870  ·  view source on GitHub ↗

Turn all the attributes into properties to simulate frozen classes.

(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])

Source from the content-addressed store, hash-verified

849
850
851def _make_frozen(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute]) -> None:
852 """Turn all the attributes into properties to simulate frozen classes."""
853 for attribute in attributes:
854 if attribute.name in ctx.cls.info.names:
855 # This variable belongs to this class so we can modify it.
856 node = ctx.cls.info.names[attribute.name].node
857 if not isinstance(node, Var):
858 # The superclass attribute was overridden with a non-variable.
859 # No need to do anything here, override will be verified during
860 # type checking.
861 continue
862 node.is_property = True
863 else:
864 # This variable belongs to a super class so create new Var so we
865 # can modify it.
866 var = Var(attribute.name, attribute.init_type)
867 var.info = ctx.cls.info
868 var._fullname = f"{ctx.cls.info.fullname}.{var.name}"
869 ctx.cls.info.names[var.name] = SymbolTableNode(MDEF, var)
870 var.is_property = True
871
872
873def _add_init(

Callers 1

Calls 3

VarClass · 0.90
SymbolTableNodeClass · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…