Closed
Description
Bug Report
A regression bug has been identified in mypy
version 1.11.1, where the use of typing.Self
in class method factory functions triggers an error. This issue does not occur in mypy
version 1.10.0. Specifically, attempting to use functools.partial
with typing.Self
results in the error: "type[Self]" not callable
.
Description generated using AI.
To Reproduce
- Create
t.py
file with the following content down below.
import functools, time, typing
class LogEntry:
def __init__(self, ts: float, msg: str) -> None:
self.ts = ts
self.msg = msg
@classmethod
async def from_msg_self_typed(cls, msg: str) -> typing.Self:
factory = functools.partial(cls, ts=time.time()) # Fails here with: "type[Self]" not callable
return factory(msg=msg)
@classmethod
async def from_msg_class_typed(cls, msg: str) -> "LogEntry":
factory = functools.partial(cls, ts=time.time()) # Works fine
return factory(msg=msg)
- Run
mypy t.py
Expected Behavior
No errors.
Actual Behavior
$ pip install mypy==1.10.0
$ mypy t.py
Success: no issues found in 1 source file
$ pip install mypy==1.11.1
t.py:11: error: "type[Self]" not callable [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
mypy 1.11.1 (compiled: yes)
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini
(and other config files): N/A - Python version used:
Python 3.11.7 (main, Dec 25 2023, 16:41:22) [Clang 15.0.0 (clang-1500.1.0.2.5)]