-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Check code after inferred UninhabitedType #4059
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! It's important to fix false negatives, since we want users to be able to trust type checking results. I have just one small comment.
mypy/types.py
Outdated
@@ -357,6 +357,7 @@ class UninhabitedType(Type): | |||
can_be_true = False | |||
can_be_false = False | |||
is_noreturn = False # Does this come from a NoReturn? Purely for error messages. | |||
ambiguous = False # Is this a result of inference for a variable without constraints? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also mention why we care about this and where this makes a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also mention why we care about this and where this makes a difference.
I added a short discussion.
This generates a bunch of new errors in Dropbox internal codebases. Since this fixes false negatives, they may just be issues in our code, but I'll have to verify it. |
I think this PR shouldn't bring anything false positive, but will be interested to see your findings. |
This PR seems to cause an invalid type to be inferred for the following code: from typing import Any
class C(dict):
def f(self, x: Any) -> None:
y = super(C, x).__new__(x)
reveal_type(y) # None, which is unexpected Previously the This works unexpectedly also on master (even when using from typing import TypeVar
T = TypeVar('T')
def f() -> T: pass
x = f()
reveal_type(x) # None The issue seems rare enough that it doesn't block merging this, but it would be nice to at least understand what is going on. |
I don't know if it is related or not, but I have seen some problems in |
I have a potential fix in a local branch. I'll have a PR out tomorrow.
…On Thu, Oct 12, 2017 at 21:02 Ivan Levkivskyi ***@***.***> wrote:
The issue seems rare enough that it doesn't block merging this, but it
would be nice to at least understand what is going on.
I don't know if it is related or not, but I have seen some problems in
meet.py with None and UninhabitedType. Another possible suspect is in
partial None types, I remember looking at it recently I didn't really
like how NoneTyp vs UninhabitedType is treated, I will check tomorrow
morning if this can be fixed quickly, if not, then I propose to merge this
and take a look at this problem later (you already opened an issue about
this).
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#4059 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABDnx_ZJ0XqTsAejW8GsFcyfyFFJKqS3ks5srnBZgaJpZM4PuPQV>
.
|
Now that #4112 was merged, the motivating example generates an error (though not all errors that we'd like) so this seems a little less urgent now. I may postpone this until the next release. |
Fixes #3994
Currently code after inferred
UninhabitedType
is silently skipped, for example no errors are shown in this code:There are other scenarios in tests. With this PR errors are shown as expected, since
UninhabitedType
s resulting from ambiguous inference don't influence binder.