Skip to content

Recognize callable in conditional type binding #1973

@abarto-machinalis

Description

@abarto-machinalis

If I run mypy against the following code:

from typing import Callable, Union

SomeFieldType = Union[str, Callable[[str], int]]

class SomeClass(object):
    def __init__(self, some_field: SomeFieldType) -> None:
        self.some_field = some_field

    def do_something(self) -> None:
        if callable(self.some_field):
            self.some_field('foobar')

it complains about self.some_field not being callable:

test_mypy.py: note: In member "do_something" of class "SomeClass":
test_mypy.py:11: error: "str" not callable

Perhaps mypy could be made aware of the "callable(...)" statements? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions