You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Corner case causes arg-type error: type is incompatible with itself #20608
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
fromcollections.abcimportCallablefromtypingimportNeverimportattrs# In the actual implementation, most classes are attrs classes, but this# appears to be the only one needed to make the bug manifest.@attrs.frozenclassValueTerm[F]:
passclassValueType[F]:
passclassBundle[T]:
data: TclassAlmostNever:
"""Replacing Never with this makes the bug disappear. At least, at this level of replication. Paring it down further causes weird behavior changes. """defbundlemethod[T, U](method: Callable[[Bundle[T]], U]) ->Callable[[T], U]:
raiseNotImplementedError@bundlemethoddeffail_value_type_inference[F](
self_bundle: Bundle[ValueTerm[F]], /
) -> (
tuple[Never, Bundle[ValueType[F]]] |tuple[int, Bundle[ValueType[F|str]]]
):
raiseNotImplementedError
The 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 with mypy 1.19.1 (compiled: yes)
Mypy command-line flags: --strict or nothing
Mypy configuration options from mypy.ini (and other config files): Was using unrelated plugin for deal, but commented out those lines, and still reproduced.
Activity
A5rocks commentedon Jan 17, 2026
Slightly minimized (and more obviously correct):
A5rocks commentedon Jan 17, 2026
Probably subtyping is broken badly for some part of this...
Remove special case for Union type context
Remove special case for Union type context
pranav-n29 commentedon Jan 20, 2026
Hey can i work on this issue is possible please assign it to me
A5rocks commentedon Jan 20, 2026
There's already a PR open to fix this.
Remove special case for Union type context (python#20610)