(ctx: mypy.plugin.ClassDefContext, attributes: list[Attribute])
| 964 | |
| 965 | |
| 966 | def _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 | |
| 983 | def _remove_hashability(ctx: mypy.plugin.ClassDefContext) -> None: |
no test coverage detected
searching dependent graphs…