Skip to content

@singledispatchmethod fails mypy validation #3898

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

Closed
cosenal opened this issue Apr 1, 2020 · 1 comment · Fixed by #3899
Closed

@singledispatchmethod fails mypy validation #3898

cosenal opened this issue Apr 1, 2020 · 1 comment · Fixed by #3899

Comments

@cosenal
Copy link

cosenal commented Apr 1, 2020

I am trying to validate the following example straight from the docs -- Here I renamed the two methods _ from the example to _int and _bool to obviate an issue already reported, i.e., python/mypy#2904

from functools import singledispatchmethod

class Negator:
    @singledispatchmethod
    def neg(self, arg):
        raise NotImplementedError("Cannot negate a")

    @neg.register
    def _int(self, arg: int):
        return -arg

    @neg.register
    def _bool(self, arg: bool):
        return not arg

n = Negator()
n.neg(2)
n.neg(True)

When I run mypy checks on this file, I get the following errors:

negator.py:17: error: "singledispatchmethod[Any]" not callable
negator.py:18: error: "singledispatchmethod[Any]" not callable
Found 2 errors in 1 file (checked 1 source file)

Python 3.8.2
mypy 0.770

hauntsaninja pushed a commit to hauntsaninja/typeshed that referenced this issue Apr 2, 2020
It doesn't actually have __call__, it does some descriptor stuff, but
this makes things work. _SingleDispatchCallable has a __call__ too,
which is what this mirrors.

Fixes python#3898
@hauntsaninja
Copy link
Collaborator

Thanks for the report! Linked PR fixes your repro for me locally.

JelleZijlstra pushed a commit that referenced this issue Apr 4, 2020
It doesn't actually have __call__, it does some descriptor stuff, but
this makes things work. _SingleDispatchCallable has a __call__ too,
which is what this mirrors.

Fixes #3898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants