Skip to content

Inconsistent Any matching with Overloads in TypeGuard/TypeIs #18659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
davidhalter opened this issue Feb 11, 2025 · 0 comments
Open

Inconsistent Any matching with Overloads in TypeGuard/TypeIs #18659

davidhalter opened this issue Feb 11, 2025 · 0 comments
Labels
bug mypy got something wrong topic-overloads

Comments

@davidhalter
Copy link

Bug Report

There is an inconsistency left where currently TypeIs/TypeGuard narrows in case of multi-Any matches, while this is not done in normal overloads. I find this strange and would prefer that it is consistent.

To Reproduce

@overload
def func1(x: str) -> TypeIs[str]:
    ...

@overload
def func1(x: int) -> TypeIs[int]:
    ...

def func1(x: Any) -> Any:
    return True

def func2(val: Any):
    if func1(val):
        reveal_type(val)  # Currently int | str


@overload
def func3(x: str) -> str:
    ...

@overload
def func3(x: int) -> int:
    ...

def func3(x: Any) -> Any:
    return True

def func4(val: Any):
    reveal_type(func3(val))  # Currently Any

Playground (used Mypy 1.15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-overloads
Projects
None yet
Development

No branches or pull requests

2 participants