Skip to content

Wrong overload resolution with alias to Any #15630

Description

@eltoder

Bug Report

Overload resolution appears to pick the first matching overload if the argument type is an alias to Any. It should consider all overloads. This works correctly when using Any directly (without an alias). This came up in python/typeshed#10405.

To Reproduce

from typing import Any, Union, overload

@overload
def my_origin(x: type) -> type: ...

@overload
def my_origin(x: Any) -> Any: ...

def my_origin(x: Any) -> Any:
    return x

def call_any(spec: Any) -> bool:
    return my_origin(spec) is Union

TypeSpec = Any

def call_alias(spec: TypeSpec) -> bool:
    return my_origin(spec) is Union

https://mypy-play.net/?mypy=latest&python=3.11&flags=strict&gist=26e08b7414caad553cd0e9549928da11

Expected Behavior

Both call_any and call_alias should type check without errors, since they are the same thing.

Actual Behavior

call_alias produces an error in strict mode:

proj/overload.py:18: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>")  [comparison-overlap]

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: --strict
  • Python version used: 3.10.6

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions