singledispatchmethod decorated method fails with unknown method register
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I played with an update of mypy from 0.931 to 0.971. The new version fails with error: "Callable[..., bool]" has no attribute "register"
The code is written oddly because of known Python issue https://bugs.python.org/issue41987 , the interpreter has no issue with it.
from functools import singledispatchmethod
class Issue:
@singledispatchmethod
def __contains__(self, other) -> bool:
return True
@Issue.__contains__.register
def _(self, other: Issue) -> bool:
return False
$ mypy issue.py
issue.py:12: error: "Callable[..., bool]" has no attribute "register"
Found 1 error in 1 file (checked 1 source file)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the issue.py reproducer with mypy and tracing how functools.singledispatchmethod is modeled, particularly the access to Issue.contains.register. The fix is complete when this example type-checks without the reported error and coverage prevents the regression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100