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 doesn't infer Union inside Tuple in an except clause #17759

Open
subnix opened this issue Sep 11, 2024 · 0 comments · May be fixed by #17762
Open

mypy doesn't infer Union inside Tuple in an except clause #17759

subnix opened this issue Sep 11, 2024 · 0 comments · May be fixed by #17762
Labels
bug mypy got something wrong

Comments

@subnix
Copy link

subnix commented Sep 11, 2024

Bug Report

If we use Union of exception types inside Tuple as a variable in an except clause, mypy produces a false-positive error.
Relates to #2816

To Reproduce

def handle(err: tuple[type[ValueError] | type[TypeError], ...]):
    try:
        return None
    except err:  # error
        pass

Gist URL: https://gist.github.com/mypy-play/dd08b2806979cb4b7228e7565046f675
Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=dd08b2806979cb4b7228e7565046f675

Expected Behavior
No error.

Actual Behavior

main.py:4: error: Exception type must be derived from BaseException (or be a tuple of exception classes)  [misc]

Your Environment

  • Mypy version used: 1.11.2
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.12
@subnix subnix added the bug mypy got something wrong label Sep 11, 2024
@subnix subnix linked a pull request Sep 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant