Skip to content

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

Closed as not planned
@ELC

Description

@ELC

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions