Skip to content

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

Closed as not planned

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

Activity

  1. added
    bugmypy got something wrong
    on Jun 19, 2023
  2. slanzmich commented on Nov 19, 2024

    @slanzmich

    This issue seems to be fixed in mypy 1.12.0.

  3. brianschubert commented on Nov 19, 2024

    @brianschubert
    Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions