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

Class _TypeCheckOnlyBaseMapper

mypy/stubtest.py:1973–1992  ·  view source on GitHub ↗

Rewrites @type_check_only instances to the nearest runtime-visible base class.

Source from the content-addressed store, hash-verified

1971
1972
1973class _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()

Callers 1

stubtest.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…