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

Variadic *args where args: Union[Tuple[...], Tuple[...], ...] are _never_ checked [False Negative] #17161

Open
finite-state-machine opened this issue Apr 24, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@finite-state-machine
Copy link

Bug Report

When args is a Union of two or more fixed-length Tuples, and some_func() is callable, the following call is always accepted without error (regardless of what's in the tuples!):

some_func(*args)

To Reproduce

[mypy-play.net]

from __future__ import annotations

from typing import (
        Tuple,
        Union,
        )

class ClassA: pass
class ClassB: pass
class ClassC: pass

def some_func(value: ClassA, /) -> None:
    pass

u_bc: Union[Tuple[ClassB], Tuple[ClassC]]
some_func(*u_bc)  # expected: [type-arg]; got: no error

Expected Behavior

Mypy should notice that one or more of the Tuples that make up the Union are not appropriate for the callable, and complain about the argument types accordingly.

Put another way, mypy should examine each possibility posed by the Union in turn, and complain if any of them isn't suitable for the variadic call.

Actual Behavior

Mypy always accepts variadic arguments of this form, without any regard to the contents of the Tuples that make up the Union.

Your Environment

  • Mypy version used: 1.9.0 (also checked 1.5, 1.0; this doesn't appear to be a recent regression)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8, 3.12
@finite-state-machine finite-state-machine added the bug mypy got something wrong label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant