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

Function erase_type

mypy/erasetype.py:41–54  ·  view source on GitHub ↗

Erase any type variables from a type. Also replace tuple types with the corresponding concrete types. Examples: A -> A B[X] -> B[Any] Tuple[A, B] -> tuple Callable[[A1, A2, ...], R] -> Callable[..., Any] Type[X] -> Type[Any]

(typ: Type)

Source from the content-addressed store, hash-verified

39
40
41def erase_type(typ: Type) -> ProperType:
42 """Erase any type variables from a type.
43
44 Also replace tuple types with the corresponding concrete types.
45
46 Examples:
47 A -> A
48 B[X] -> B[Any]
49 Tuple[A, B] -> tuple
50 Callable[[A1, A2, ...], R] -> Callable[..., Any]
51 Type[X] -> Type[Any]
52 """
53 typ = get_proper_type(typ)
54 return typ.accept(EraseTypeVisitor())
55
56
57class EraseTypeVisitor(TypeVisitor[ProperType]):

Callers 8

infer_partial_typeMethod · 0.90
visit_instanceMethod · 0.90
covers_at_runtimeFunction · 0.90
assert_eraseMethod · 0.90
visit_union_typeMethod · 0.85

Calls 3

get_proper_typeFunction · 0.90
EraseTypeVisitorClass · 0.85
acceptMethod · 0.45

Tested by 1

assert_eraseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…