Skip to content
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

mypy's inference gets confused about unions with typevartuple #18407

Open
A5rocks opened this issue Jan 2, 2025 · 0 comments · May be fixed by #18408
Open

mypy's inference gets confused about unions with typevartuple #18407

A5rocks opened this issue Jan 2, 2025 · 0 comments · May be fixed by #18408
Labels
bug mypy got something wrong topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@A5rocks
Copy link
Contributor

A5rocks commented Jan 2, 2025

Bug Report

In some cases involving matching an argument against a union with type var tuples, mypy infers Never instead of something better.

To Reproduce

from typing import TypeVarTuple, Unpack, Generic
from collections.abc import Callable

Args = TypeVarTuple("Args")

class Built(Generic[Unpack[Args]]):
    pass

def example(n: Built[Unpack[Args]] | Callable[[Unpack[Args]], None]) -> Built[Unpack[Args]]: ...

reveal_type(example)  # N: Revealed type is "def [Args] (n: Union[__main__.Built[Unpack[Args`-1]], def (*Unpack[Args`-1])]) -> __main__.Built[Unpack[Args`-1]]"

@example  # E: Argument 1 to "example" has incompatible type "Callable[[], None]"; expected "Built[*tuple[Never, ...]] | Callable[[VarArg(Never)], None]"
def command1() -> None:
    return

Expected Behavior

I expect no error.

Your Environment

Checked in mypy playground.

  • Mypy version used: v1.14
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12
@A5rocks A5rocks added the bug mypy got something wrong label Jan 2, 2025
@hamdanal hamdanal added the topic-pep-646 PEP 646 (TypeVarTuple, Unpack) label Jan 5, 2025
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-pep-646 PEP 646 (TypeVarTuple, Unpack)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants