Turn all the attributes into properties to simulate frozen classes.
(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])
| 849 | |
| 850 | |
| 851 | def _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 | |
| 873 | def _add_init( |
no test coverage detected
searching dependent graphs…