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
$ mypy demo.py
demo.py:7: error: Unsupported operand types for + ("int" and "None")
demo.py:7: error: Unsupported operand types for + ("None" and "int")
demo.py:7: error: Unsupported left operand typefor + ("None")
demo.py:7: note: Both left and right operands are unions
Found 3 errors in 1 file (checked 1 source file)
Expected Behavior
$ mypy demo.py
Success: no issues found in 1 source file
A question for the developers: should I file a separate issue for the following or is it the same one in essence?
def handle(parts: Optional[List[str]]) -> None:
"""Handle a list... or not."""
if parts not in (None,):
pset = set(parts)
print(f"Handling {pset!r}")
else:
print("Nothing to handle")
If the check is if parts is not None:, mypy handles it just fine, but the above fails.
Bug Report
False positive when an
Optional
is unpacked withNone not in
.To Reproduce
demo.py
:Actual Behavior
Expected Behavior
In fact, the 2 expression should be the same:
Your Environment
$ mypy --version mypy 0.910 $ python --version Python 3.8.10 $ uname -a Linux yan-p520c 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal
The text was updated successfully, but these errors were encountered: