-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
False positive on _
(underscore) as variable name with disallow-any-expr
#15253
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
The code provided contains two errors when calling the wrapper function. I will explain each error and provide a corrected version of the code. Error: Missing argument in wrapper function call Correction: Error: Incorrect number of values to unpack Correction: `from typing import Callable, Tuple, TypeVar T = TypeVar("T") def wrapper(fn: Callable[[], T]) -> Tuple[T, float]: def wrapper2(fn: Callable[[], T]) -> T: def func() -> int: def a() -> None: _, c = #`wrapper(func)`` |
from typing import Callable, Tuple, TypeVar T = TypeVar("T") def wrapper(fn: Callable[[], T]) -> Tuple[T, float]: def wrapper2(fn: Callable[[], T]) -> T: def func() -> int: def a() -> None: _, c = wrapper(func) I hope this code will rectify the error.. |
@AVUKU-PRAGATHESWARI Sorry, I don't think your answer is correct. (And, no offence, but I doubt if I'm talking to human.) |
I am a human😊...But its fine |
Here's a more minimal reproduction!: # flags: --disallow-any-expr
from typing import Tuple, TypeVar
T = TypeVar("T")
def f(x: T) -> Tuple[T, float]: ...
def a() -> None:
_ = f(42) It only shows a single error, though. ... Oh, it's cause this: Lines 3737 to 3741 in 2ede35f
Uhhhhhhhhhhh, I'll think about this. |
For what it's worth, widening the special case that allows |
@ilevkivskyi you initially added this special case in 626ff689e6df171e1aec438b905efdf999bdc09e Do you know of how it could maybe generalize? Or if this is just some issue that takes more effort than warranted. I see you added a comment right above about some sort of solution, but I'm not exactly sure of what this entails or whether maybe there's a better way nowadays:
Specifically, mypy is seeing a |
@ilevkivskyi again in case you haven't seen this yet I found another case of this in some code a friend wrote |
That special-casing is really fragile, I wouldn't modify it (either way) unless really needed. I think the problem here may be that kind of Btw I think |
here's a more minimal example: def foo() -> None:
_ = 1
assert _ == 1 # error |
Hm, unfortunately my idea uncovered a big underlying issue, see #15497 (comment) |
Bug Report
mypy gives a false positive with variable
_
(underscore) under certain circumstances (see repro).To Reproduce
https://mypy-play.net/?mypy=latest&python=3.8&flags=disallow-any-expr&gist=bca874771ec5eba30815133c9bbd4ab7
Interestingly only one line causes the error:
_
Actual Behavior
Your Environment
(environment of the playground)
--disallow-any-expr
The text was updated successfully, but these errors were encountered: