Skip to content

Calling callable in an if-condition makes mypy think branch in unreachable #3605

@ilinum

Description

@ilinum

In the following code, mypy thinking callable(o) always returns False. This might be related to #3603.

def f(o: object) -> None:
    if callable(o):
        # this branch is not typechecked
        o()
        1 + 'boom'  # no error from mypy
        o()

f(lambda: print('hello'))

Here is the output from mypy and python.

$ mypy n.py 
$ python3 n.py 
hello
Traceback (most recent call last):
  File "n.py", line 8, in <module>
    f(lambda: print('hello'))
  File "n.py", line 5, in f
    1 + 'boom'
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions