python / python/mypy

`assert_type` fails to fail for `NoReturn`

Open
#16,319 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

In a case that mypy deems impossible (i.e. type narrowed to NoReturn), it's currently impossible to cause assert_type to fail.

Similarly, reveal_type has no effect in the case of NoReturn.

To Reproduce

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

Expected Behavior

Three assert_type failures.

Actual Behavior

Only one assert_type failure.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked mypy-play reproduction and compare the three expected assert_type failures with the single actual failure. Trace how assert_type and reveal_type handle a type narrowed to NoReturn, then add regression coverage for this case. Done means all three assertions fail as expected and the corresponding reveal_type behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.