Skip to content

assert_never not being properly handled when using TypeVars bound to Union Type #15467

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

Closed
ELC opened this issue Jun 19, 2023 · 2 comments
Closed
Labels
bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder topic-type-variables

Comments

@ELC
Copy link

ELC commented Jun 19, 2023

Bug Report

When using exhaustive checking either in if/elif/else or with match over TypeVars bound to Union Types mypy throws:

Argument 1 to "assert_never" has incompatible type "T"; expected "NoReturn"  [arg-type]
expected "NoReturn"  [arg-type]

Whereas this should have been the expected behavior and no errors should be raised.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=c90f6c776bc8d64645075dee9bf15032

Expected Behavior

The expected behavior should be identical as if operating over the Union Type, not throwing erros as the type has been exhausted,

Actual Behavior

An error is shown:

Argument 1 to "assert_never" has incompatible type "T"; expected "NoReturn"  [arg-type]
expected "NoReturn"  [arg-type]

Your Environment

  • Mypy version used: 1.3.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11
@slanzmich
Copy link

This issue seems to be fixed in mypy 1.12.0.

@brianschubert
Copy link
Collaborator

Thanks! Duplicate of #15235, this was fixed in #17850

@brianschubert brianschubert closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 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 topic-type-narrowing Conditional type narrowing / binder topic-type-variables
Projects
None yet
Development

No branches or pull requests

4 participants