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
Oh, that's weird. I didn't even know mypy accepts that! Agreed it would be better to flag as error. (Outside stubs, and not in type comments of course.)
This partially, but not completely, resolvespython#3088
Previously, code of the following form was accepted by mypy:
class A:
def foo(self) -> A:
...
This results in an error at runtime because 'A' is not yet defined.
This pull request modifies the parsing process to report an error when
a type is being incorrectly used within its class definition.
However, this commit does *not* attempt to handle other cases where
the user is using a type that is undefined at runtime. For example, mypy
will continue to accept the following code without an error:
def f() -> A:
...
class A:
...
I decided it would probably be best to address this in a future pull
request.
This type checks, but crashes in runtime with
NameError
:I think it's better if mypy reported an error
Name "A" should be a forward reference
.The text was updated successfully, but these errors were encountered: