Skip to content

Commit 8621197

Browse files
authored
Add a test of evaluating a type with a link in its attrs (#17)
I was poking around at #13, thinking about to what extent the various data structures there can be unified, and noticed that no tests failed if I got rid of `seen`! That seemed wrong, so I wrote some tests to catch those cases. (Without seen, we blow the stack.) Note that in these cases (of classes), not only do we want to not blow the stack, but we would like the recursively referenced type to be identical to the top-level one. (Whereas I think for *type aliases*, I think that is not what we want, since it probably wouldn't pretty print correctly?)
1 parent 3c6a50a commit 8621197

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_type_dir.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,37 @@ class Final(Mine, Ordinary, Wrapper[float], AnotherBase[float], Last[int]):
154154
]
155155

156156

157+
# Subtyping this forces real type evaluation
158+
class Eval[T]:
159+
pass
160+
161+
162+
class Loop(Eval[int]):
163+
loop: Loop
164+
165+
166+
class Foo(Eval[int]):
167+
bar: Bar
168+
169+
170+
class Bar(Eval[float]):
171+
foo: Foo
172+
173+
174+
def test_type_dir_link_1():
175+
d = eval_typing(Loop)
176+
loop = d.__annotations__["loop"]
177+
assert loop is d
178+
assert loop is not Foo
179+
180+
181+
def test_type_dir_link_2():
182+
d = eval_typing(Foo)
183+
loop = d.__annotations__["bar"].__annotations__["foo"]
184+
assert loop is d
185+
assert loop is not Foo
186+
187+
157188
def test_type_dir_1():
158189
d = eval_typing(Final)
159190

0 commit comments

Comments
 (0)