Rewrites @type_check_only instances to the nearest runtime-visible base class.
| 1971 | |
| 1972 | |
| 1973 | class _TypeCheckOnlyBaseMapper(mypy.types.TypeTranslator): |
| 1974 | """Rewrites @type_check_only instances to the nearest runtime-visible base class.""" |
| 1975 | |
| 1976 | def visit_instance(self, t: mypy.types.Instance, /) -> mypy.types.Type: |
| 1977 | instance = mypy.types.get_proper_type(super().visit_instance(t)) |
| 1978 | assert isinstance(instance, mypy.types.Instance) |
| 1979 | |
| 1980 | if instance.type.is_type_check_only: |
| 1981 | # find the nearest non-@type_check_only base class |
| 1982 | for base_info in instance.type.mro[1:]: |
| 1983 | if not base_info.is_type_check_only: |
| 1984 | return map_instance_to_supertype(instance, base_info) |
| 1985 | |
| 1986 | msg = f"all base classes of {instance.type.fullname!r} are @type_check_only" |
| 1987 | assert False, msg |
| 1988 | |
| 1989 | return instance |
| 1990 | |
| 1991 | def visit_type_alias_type(self, t: mypy.types.TypeAliasType, /) -> mypy.types.Type: |
| 1992 | return t |
| 1993 | |
| 1994 | |
| 1995 | _TYPE_CHECK_ONLY_BASE_MAPPER = _TypeCheckOnlyBaseMapper() |
no outgoing calls
no test coverage detected
searching dependent graphs…