Skip to content

Expression has type "function", variable has type "Callable[[], None]" #10740

Closed
@FFY00

Description

@FFY00

To Reproduce

from typing import Callable

class Test:
    def method1(self) -> None:
        pass

    def method2(self, optional: int = 0) -> None:
        pass

    def test(self, something: bool) -> None:
        action: Callable[[], None]
        action = self.method1 if something else self.method2

Expected Behavior

I believe the code above should validate in mypy.

Actual Behavior

$ mypy example.py
example.py:12: error: Incompatible types in assignment (expression has type "function", variable has type "Callable[[], None]")
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.5
  • Operating system and version: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions