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

Function _add_slots

mypy/plugins/attrs.py:949–963  ·  view source on GitHub ↗
(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])

Source from the content-addressed store, hash-verified

947
948
949def _add_slots(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute]) -> None:
950 if any(p.slots is None for p in ctx.cls.info.mro[1:-1]):
951 # At least one type in mro (excluding `self` and `object`)
952 # does not have concrete `__slots__` defined. Ignoring.
953 return
954
955 # Unlike `@dataclasses.dataclass`, `__slots__` is rewritten here.
956 ctx.cls.info.slots = {attr.name for attr in attributes}
957
958 # Also, inject `__slots__` attribute to class namespace:
959 slots_type = TupleType(
960 [ctx.api.named_type("builtins.str") for _ in attributes],
961 fallback=ctx.api.named_type("builtins.tuple"),
962 )
963 add_attribute_to_class(api=ctx.api, cls=ctx.cls, name="__slots__", typ=slots_type)
964
965
966def _add_match_args(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute]) -> None:

Callers 1

Calls 4

TupleTypeClass · 0.90
add_attribute_to_classFunction · 0.90
anyFunction · 0.85
named_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…