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

Function _add_match_args

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

Source from the content-addressed store, hash-verified

964
965
966def _add_match_args(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute]) -> None:
967 if (
968 "__match_args__" not in ctx.cls.info.names
969 or ctx.cls.info.names["__match_args__"].plugin_generated
970 ):
971 str_type = ctx.api.named_type("builtins.str")
972 match_args = TupleType(
973 [
974 str_type.copy_modified(last_known_value=LiteralType(attr.name, fallback=str_type))
975 for attr in attributes
976 if not attr.kw_only and attr.init
977 ],
978 fallback=ctx.api.named_type("builtins.tuple"),
979 )
980 add_attribute_to_class(api=ctx.api, cls=ctx.cls, name="__match_args__", typ=match_args)
981
982
983def _remove_hashability(ctx: mypy.plugin.ClassDefContext) -> None:

Callers 1

Calls 5

TupleTypeClass · 0.90
LiteralTypeClass · 0.90
add_attribute_to_classFunction · 0.90
named_typeMethod · 0.45
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…