Open
Description
Bug Report
Mypy outputs the wrong error message when analyzing the code given below, but only when its on-disk cache is hot.
I infer the cache is the issue based on:
- the issue doesn't manifest the 1st time mypy is run with any given configuration (version, flags, etc.), but occurs every time thereafter
- deleting
.mypy_cache
allows mypy to operate correctly for one run only - the issue never manifests if
--no-incremental
is included on the command-line
To Reproduce
[zip] bug.py
is:
from __future__ import annotations
from typing import *
class SomeMeta(type):
def __prepare__(
metacls, name: str, bases: Tuple[type, ...], /, **kwds: Any
) -> Mapping[str, object]:
return super().__prepare__(name, bases, **kwds)
Run mypy on this script twice.
(mypy-play.net cannot reproduce this issue)
Actual behaviour
Run results (other than the 1st run):
$ python3 -m mypy bug.py
bug.py:6: error: Signature of "__prepare__" incompatible with supertype "type" [override]
bug.py:6: note: Superclass:
bug.py:6: note: def __prepare__(metacls, str, Tuple[type, ...], /, **kwds: Any) -> Mapping[str, object]
bug.py:6: note: Subclass:
bug.py:6: note: def __prepare__(metacls, str, Tuple[type, ...], /, **kwds: Any) -> Mapping[str, object]
Found 1 error in 1 file (checked 1 source file)
Note that mypy's output reads roughly:
Superclass:
<some signature>
Subclass:
<exactly the same signature>
Expected Behavior
Mypy should output:
bug.py:6: error: Signature of "__prepare__" incompatible with supertype "type" [override]
bug.py:6: note: Superclass:
bug.py:6: note: @classmethod
bug.py:6: note: def __prepare__(metacls, str, Tuple[type, ...], /, **kwds: Any) -> Mapping[str, object]
bug.py:6: note: Subclass:
bug.py:6: note: def __prepare__(metacls, str, Tuple[type, ...], /, **kwds: Any) -> Mapping[str, object]
Found 1 error in 1 file (checked 1 source file)
Note the appearance of @classmethod
under Superclass
.
Related issues
This might relate to #10366.
Your Environment
- Mypy version used: 1.8.0
- Mypy command-line flags: none necessary, but changing flags will result in the expected behaviour one time only
- Mypy configuration options from
mypy.ini
(and other config files): (presumably the same as command-line flags) - Python version used: 3.8, 3.12