-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Please just change something. Weird combination of dead code and inferred None #10634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I set |
Having def foo(val: str) -> None:
if not isinstance(val, str):
raise TypeError("Bad!") |
I think |
related #11223 |
I think the problem here is that mypy is inferring a partial None for I suppose mypy could try rechecking With foo = None # E: Need type annotation for "foo"
def bar() -> str: # E: Missing return statement
global foo
if foo is not None:
print("Hello")
else:
foo = "bar"
return "lol" which is a lot closer to what I'd expect. Merging #10169 would make |
I agree that |
Feature
This program type-checks, even though it's obviously wrong. It's not a bug, it's a feature:
foo
isNone
, even thoughOptional[str]
was intended.foo
has typeNone
, theif foo is not None:
part is eliminated as dead code, and therefore the missing return isn't detected.foo = "bar"
,reveal_type(foo)
showsstr
. Perhaps the assignment should be an error?Pitch
A friend submitted a PR like this and thought it was fine.
The text was updated successfully, but these errors were encountered: