arguments list is empty if define __call__ as attribute of class
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
arguments list is empty if define __call__ as attribute of class
To Reproduce
import typing
class Bug:
__slots__ = ("__call__",)
__call__: typing.Callable[[int], bytes]
@staticmethod
def test(_x: int) -> bytes:
return b""
def __init__(self) -> None:
self.__call__ = Bug.test
def bug() -> typing.Callable[[int], bytes]:
return Bug()
if __name__ == "__main__":
bug()
Expected Behavior
pass
Actual Behavior
test.py:17: error: Incompatible return value type (got "Bug", expected "Callable[[int], bytes]") [return-value]
test.py:17: note: "Bug.__call__" has type "Callable[[], bytes]"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.8.0
- Mypy command-line flags: --strict test.py
- Mypy configuration options from
mypy.ini(and other config files): default mypy, no config - Python version used: CPython 3.11.6
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
No repository file or test is named. Start by saving the supplied example as test.py and running mypy --strict test.py; then trace how mypy types a class instance whose call is declared as a slot attribute. Done means the example passes without the incompatible return-value error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100