You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportTypeclassFoo:
def__init__(self):
classBar:
passself.Bar: Type[Bar] =Barfoo=Foo()
bar: foo.Bar=foo.Bar()
reveal_type(foo.Bar)
reveal_type(bar)
results in the following slightly confusing and seemingly contradictory output:
example.py:11: error: Name 'foo.Bar' is not defined # on bar: foo.Bar
example.py:13: note: Revealed type is 'Type[example.Bar@5]' # on reveal_type(foo.Bar)
example.py:14: note: Revealed type is 'Any' # on reveal_type(bar)
Ideally, I would have expected reveal_type(bar) to reveal example.Bar@5. I'm not sure if there is a way to correctly type this code without resorting to # type: ignore right now.
Tested on mypy 0.761, Python 3.8.1.
The text was updated successfully, but these errors were encountered:
Although the error message is not perfect it is technically correct. Type named foo.Bar can't be statically resolved.
On one hand, this is a really bad pattern, since a new nested class will be created on each instantiation: Foo().Bar and Foo().Bar are two different classes. On the other hand this (surprisingly to me) not the first time this issue appears. So it would make sense to improve the error message.
This is strictly about the seemingly contradictory 'foo.Bar' is not defined when the type is, in fact, known to mypy, just incompatible with an attempt at static typing.
Apologies if I wasn't clear in the original report 😅
Running mypy on the following example:
results in the following slightly confusing and seemingly contradictory output:
Ideally, I would have expected
reveal_type(bar)
to revealexample.Bar@5
. I'm not sure if there is a way to correctly type this code without resorting to# type: ignore
right now.Tested on mypy 0.761, Python 3.8.1.
The text was updated successfully, but these errors were encountered: