Classmethod bound with an additional name trigger stubtest errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Classmethods bound with an additional name trigger stubtest errors.
To Reproduce
Consider the following trivial module and companion typing stub file
# mod.py
class T:
def a(self): pass
b = a
@classmethod
def c(cls): pass
d = c
# mod.pyi
class T:
def a(self) -> None: pass
b = a
@classmethod
def c(cls) -> None: pass
d = c
then run stubtest the following way:
PYTHONPATH=$PWD stubtest mod
Expected Behavior
stubtest succeeds with no output printed
Actual Behavior
error: mod.T.d variable differs from runtime type def () -> Any
Stub: in file /home/dalcinl/tmp/pkg/mod.pyi:6
def (cls: Type[mod.T])
Runtime: in file /tmp/mod.py:4
<bound method T.c of <class 'mod.T'>>
Found 1 error (checked 1 module)
Please note that the issue comes from a @classmethod, a regular method does not trigger the error.
Your Environment
- Mypy version used: 1.4.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.11.4
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
Reproduce the report with the paired mod.py and mod.pyi examples and run PYTHONPATH=$PWD stubtest mod. Compare how stubtest handles T.c and the alias T.d, then verify the change against this reproduction; done means the command succeeds without output or errors.
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
- Clearly specified
- Newbie friendliness
- 50/100