recognize staticmethod's __func__
Open
Nobody has claimed this yet.
bug
topic-descriptors
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
To Reproduce
Run mypy against this code
class A(object):
@staticmethod
def open():
return 123
@staticmethod
def proccess():
return 456
switch = {
1: open.__func__,
2: proccess.__func__,
}
p.s. this code snippet is copied from the first solution of https://stackoverflow.com/questions/41921255/staticmethod-object-is-not-callable
Expected Behavior
This code snippet should pass mypy's check.
Actual Behavior
s.py:10: error: "Callable[[], Any]" has no attribute "__func__"
s.py:11: error: "Callable[[], Any]" has no attribute "__func__"
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: just file name
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.7
- Operating system and version: Debian rodete
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 supplied staticmethod example with mypy and inspect how the type checker handles func access on the decorated methods. Trace the relevant staticmethod typing behavior and add or update a regression test for this snippet; done means the example passes mypy without the reported attribute 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
- Mostly clear
- Newbie friendliness
- 45/100