Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Incompatible types in assignment" on assignment of ternary operator of instances of classes with __call__ #16824

Closed
ZeeD opened this issue Jan 26, 2024 · 1 comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions

Comments

@ZeeD
Copy link

ZeeD commented Jan 26, 2024

Bug Report

I'm facing a false positive with the ternary assignment on a callable

To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=e0b946c6f8cc1379b98c755cdc773b92

from collections.abc import Callable

class Foo:
    def __call__(self) -> None: ...
class Bar:
    def __call__(self) -> None: ...

def foo() -> None: ...
def bar() -> None: ...

def fun(b: bool) -> None:
    error: Callable[[], None] = Foo() if b else Bar()

    workaround: Callable[[], None]
    if b:
        workaround = Foo()
    else:
        workaround = Bar()

    noerror: Callable[[], None] = foo if b else bar

Expected Behavior
No errors

Actual Behavior

Incompatible types in assignment (expression has type "object", variable has type "Callable[[], None]") [assignment]

Your Environment

mypy 1.8.0 (compiled: yes)
strict = true
Python 3.12.1

(edit: simplified example)

@ZeeD ZeeD added the bug mypy got something wrong label Jan 26, 2024
@ZeeD ZeeD changed the title "Incompatible types in assignment" on callable return type related to classes __call__ methods "Incompatible types in assignment" on assignment of ternary operator of instances of classes with __call__ Jan 26, 2024
@JelleZijlstra JelleZijlstra added the topic-join-v-union Using join vs. using unions label Jan 26, 2024
@hauntsaninja
Copy link
Collaborator

Fixed in #17427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions
Projects
None yet
Development

No branches or pull requests

3 participants