Skip to content

Corner case causes arg-type error: type is incompatible with itself #20608

Closed

Description

@mwchase

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 NotImplementedError

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.
  • Python version used: Python 3.13.11

Activity

  1. A5rocks commented on Jan 17, 2026

    @A5rocks
    Collaborator

    Slightly minimized (and more obviously correct):

    from collections.abc import Callable
    from typing import Never
    
    class ValueType[F]:
        pass
    
    
    class Bundle[T]:
        pass
    
    
    def fail_value_type_inference[F](
        self_bundle: ValueType[F]
    ) -> (
        tuple[Never, Bundle[ValueType[F]]] | tuple[int, Bundle[ValueType[int]]]
    ):
        raise NotImplementedError
    
    x = fail_value_type_inference
    x = fail_value_type_inference  # E
  2. A5rocks commented on Jan 17, 2026

    @A5rocks
    Collaborator

    Probably subtyping is broken badly for some part of this...

  3. added 2 commits that reference this issue on Jan 17, 2026
    3535666
    1343985
  4. pranav-n29 commented on Jan 20, 2026

    @pranav-n29

    Hey can i work on this issue is possible please assign it to me

  5. A5rocks commented on Jan 20, 2026

    @A5rocks
    Collaborator

    Hey can i work on this issue is possible please assign it to me

    There's already a PR open to fix this.

  6. added a commit that references this issue on Jan 21, 2026
    61b3b5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions