In the following example, the branch of an if-statement is not being typechecked.
classParent1: passclassParent2: passclassChild(Parent1, Parent2): passdefgoo(p: Parent1) ->None:
ifisinstance(p, Parent2):
# this branch is not typechecked1+'boom'# no error from mypy here.goo(Child())
Here is the output from mypy and python.
$ mypy i.py $ python3 i.py Traceback (most recent call last):
File "i.py", line 13, in <module>
goo(Child())
File "i.py", line 10, in goo
1 + 'boom' # no error from mypy but there's an error at runtime
TypeError: unsupported operand type(s) for +: 'int' and 'str'
In the following example, the branch of an if-statement is not being typechecked.
Here is the output from
mypyandpython.