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
The following results in MyPy complaining Incompatible types in assignment (expression has type "unicode", variable has type "int"):
ints_n_txt = [(1, u'1'), (2, u'2'), (3, u'3')] # type: List[Tuple[int, Text]]
for _, _ in ints_n_txt: # _ has two different types
pass
Unsurprisingly, this affects collection comprehension as well:
spam = [True for _, _ in ints_n_txt] # type: List[bool]
Explicitly declaring the type of _ as Any "fixes" the error for the for loop:
_ = None # type: Any
for _, _ in …
But that doesn't work for collection comprehension. (MyPy will still complain, and some linters will too. For example, flake8 will complain that F812 - list comprehension redefines '_' from line ….)
These seem to work, but both look a little awkward:
for (
_, # type: ignore
_, # type: ignore
) in ints_n_txt:
pass
spam = [
True for (
_, # type: ignore
_, # type: ignore
) in ints_n_txt
] # type: List[bool]
This may be as intended. I'm wondering if treating _ in all scopes as type Any by default is a bad idea? (Apologies if this is more appropriately filed as an issue with typeshed.)
The text was updated successfully, but these errors were encountered:
The following results in MyPy complaining
Incompatible types in assignment (expression has type "unicode", variable has type "int")
:Unsurprisingly, this affects collection comprehension as well:
Explicitly declaring the type of
_
asAny
"fixes" the error for thefor
loop:But that doesn't work for collection comprehension. (MyPy will still complain, and some linters will too. For example,
flake8
will complain thatF812 - list comprehension redefines '_' from line …
.)These seem to work, but both look a little awkward:
This may be as intended. I'm wondering if treating
_
in all scopes as typeAny
by default is a bad idea? (Apologies if this is more appropriately filed as an issue withtypeshed
.)The text was updated successfully, but these errors were encountered: