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

Class TypeFixture

mypy/test/typefixture.py:42–399  ·  view source on GitHub ↗

Helper class that is used as a fixture in type-related unit tests. The members are initialized to contain various type-related values.

Source from the content-addressed store, hash-verified

40
41
42class TypeFixture:
43 """Helper class that is used as a fixture in type-related unit tests.
44
45 The members are initialized to contain various type-related values.
46 """
47
48 def __init__(self, variance: int = COVARIANT) -> None:
49 # The 'object' class
50 self.oi = self.make_type_info("builtins.object") # class object
51 self.o = Instance(self.oi, []) # object
52
53 # Type variables (these are effectively global)
54
55 def make_type_var(
56 name: str, id: int, values: list[Type], upper_bound: Type, variance: int
57 ) -> TypeVarType:
58 return TypeVarType(
59 name,
60 name,
61 TypeVarId(id),
62 values,
63 upper_bound,
64 AnyType(TypeOfAny.from_omitted_generics),
65 variance,
66 )
67
68 self.t = make_type_var("T", 1, [], self.o, variance) # T`1 (type variable)
69 self.tf = make_type_var("T", -1, [], self.o, variance) # T`-1 (type variable)
70 self.tf2 = make_type_var("T", -2, [], self.o, variance) # T`-2 (type variable)
71 self.s = make_type_var("S", 2, [], self.o, variance) # S`2 (type variable)
72 self.s1 = make_type_var("S", 1, [], self.o, variance) # S`1 (type variable)
73 self.sf = make_type_var("S", -2, [], self.o, variance) # S`-2 (type variable)
74 self.sf1 = make_type_var("S", -1, [], self.o, variance) # S`-1 (type variable)
75 self.u = make_type_var("U", 3, [], self.o, variance) # U`3 (type variable)
76
77 # Simple types
78 self.anyt = AnyType(TypeOfAny.special_form)
79 self.nonet = NoneType()
80 self.uninhabited = UninhabitedType()
81 self.a_uninhabited = UninhabitedType()
82 self.a_uninhabited.ambiguous = True
83
84 # Abstract class TypeInfos
85
86 # class F
87 self.fi = self.make_type_info("F", is_abstract=True)
88
89 # class F2
90 self.f2i = self.make_type_info("F2", is_abstract=True)
91
92 # class F3(F)
93 self.f3i = self.make_type_info("F3", is_abstract=True, mro=[self.fi])
94
95 # Class TypeInfos
96 self.std_tuplei = self.make_type_info(
97 "builtins.tuple", mro=[self.oi], typevars=["T"], variances=[COVARIANT]
98 ) # class tuple
99 self.type_typei = self.make_type_info("builtins.type") # class type

Callers 11

setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
make_tupleMethod · 0.90

Calls

no outgoing calls

Tested by 11

setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
setUpMethod · 0.72
make_tupleMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…