-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
With a very specific combination of features, Mypy rejects a decorator application, claiming that a callable type is incompatible with apparently the same callable type.
To Reproduce
from collections.abc import Callable
from typing import Never
import attrs
# In the actual implementation, most classes are attrs classes, but this
# appears to be the only one needed to make the bug manifest.
@attrs.frozen
class ValueTerm[F]:
pass
class ValueType[F]:
pass
class Bundle[T]:
data: T
class AlmostNever:
"""Replacing Never with this makes the bug disappear.
At least, at this level of replication. Paring it down further causes weird
behavior changes.
"""
def bundlemethod[T, U](method: Callable[[Bundle[T]], U]) -> Callable[[T], U]:
raise NotImplementedError
@bundlemethod
def fail_value_type_inference[F](
self_bundle: Bundle[ValueTerm[F]], /
) -> (
tuple[Never, Bundle[ValueType[F]]] | tuple[int, Bundle[ValueType[F | str]]]
):
raise NotImplementedErrorThe code that hit this was using Generator instead of tuple.
Actual Behavior
mypy_repro.py:34: error: Argument 1 to "bundlemethod" has incompatible type "Callable[[Bundle[ValueTerm[F]]], tuple[Never, Bundle[ValueType[F]]] | tuple[int, Bundle[ValueType[F | str]]]]"; expected "Callable[[Bundle[ValueTerm[F]]], tuple[Never, Bundle[ValueType[F]]] | tuple[int, Bundle[ValueType[F | str]]]]" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
mypy 1.20.0+dev.3cae656ce264f00ac5417b0559a8cba1453f5eb5 (compiled: no)also encountered withmypy 1.19.1 (compiled: yes) - Mypy command-line flags:
--strictor nothing - Mypy configuration options from
mypy.ini(and other config files): Was using unrelated plugin fordeal, but commented out those lines, and still reproduced. - Python version used:
Python 3.13.11
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong