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

Assignment through def does not satisfy ABC's Optional Callable with args #13194

Closed
r1chardj0n3s opened this issue Jul 19, 2022 · 0 comments · Fixed by #18847
Closed

Assignment through def does not satisfy ABC's Optional Callable with args #13194

r1chardj0n3s opened this issue Jul 19, 2022 · 0 comments · Fixed by #18847
Labels
bug mypy got something wrong

Comments

@r1chardj0n3s
Copy link

It is not possible to satisfy an ABC that has an Optional Callable with args defined using a "def" in the concrete class.

A Callable which is not optional may be defined.

An Optional Callable with no arguments may also be defined.

Reproduction of the problem using mypy version 0.961 in the mypy playground.

The cases Two and Three below should be accepted as suitable implementations of check, and they are not.

import abc
from typing import Callable, Optional

# optional callable with an argument define
class OptCallArgs(abc.ABC):
    check: Optional[Callable[[int], None]]

# assignment of a callable is fine
class One(OptCallArgs):
    check = lambda value: None

# "def" of a suitable callable is not handled
class Two(OptCallArgs):
    @staticmethod
    def check(value: int): ...

class Three(OptCallArgs):
    def check(self, value: int): ...

# callable with args has no issue
class CallArgs(abc.ABC):
    check: Callable[[int], None]

class Four(CallArgs):
    def check(self, value: int): ...

# optional callable does not have an issue if there are no args
class OptCall(abc.ABC):
    check: Optional[Callable]

class Five(OptCall):
    def check(self): ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant