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
$ cat b.py
from typing import Optional
class A:
x: Optional[str]
def f(a: A) -> None:
if not a.x:
pass
elif a.x == "x":
a = A()
else:
y: str = a.x
$ mypy b.py
b.py:12: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str")
$ mypy --version
mypy 0.701
The assignment a = A() should not affect the code in the else branch.
The text was updated successfully, but these errors were encountered:
importtypingdefto_int(text: str) ->typing.Union[int, str]:
""" Cast to integer if value is numeric or return unchanged """iftext.isnumeric():
result=int(text)
else:
result=textreturnresult
$ mypy asdf.py
asdf.py:8: error: Incompatible types in assignment (expression has type"str", variable has type"int")
The assignment
a = A()
should not affect the code in theelse
branch.The text was updated successfully, but these errors were encountered: