-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Spurious "Expression has type Any" error following attribute access #5842
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 aside some time and followed the debugging technique suggested by @gvanrossum. First, while experimenting, I changed the code snippet given above a bit to see if it fails for different kinds of operations (yes, it does): def access_before_declaration(self) -> None:
obj = Object('foo')
obj.value
x = [1]
print(x[1]) # Expression has type "Any"
# ... The error is triggered in
Most of the logic for determining the type of the node happens in
A few steps later,
With To me it seems that the deduction of This is my first look at the code base though, so maybe someone more familiar with the inner |
Just a small update, this can still be reproduced on the latest mypy:
(Almost the same result as before, now with an additional FYI, we use |
I think there may be a very simple fix: don't emit this error if current node is deferred, i.e. add a |
Is this expected to still be a problem in mypy 0.560? The problem code:
|
@MasonRemaley 0.560 is very old. Could you try a newer release? |
Huh, I attempted to update to the latest version w/ pip before reporting this, but I must have misunderstand pip's CLI or something. I uninstalled and reinstalled, got version 0.782, and now it works. Thanks! :) |
As originally described in #5788, I've run into a problem with
--disallow-any-expr
reporting spurious errors.Consider the following file
any.py
:Running mypy on it produces:
What we see is that
x
is correctly identified asint
inaccess_after_declaration
, but incorrectly asAny
inaccess_before_declaration
. The error is only triggered in very specific circumstances:The text was updated successfully, but these errors were encountered: