Skip to content

Multiple Inheritance Makes Mypy think an if branch is unreachable. #3603

Description

@ilinum

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'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions