Skip to content

[ty] reveal_type diagnostics in unreachable code#24070

Merged
sharkdp merged 2 commits intomainfrom
david/reveal_type-unreachable
Mar 20, 2026
Merged

[ty] reveal_type diagnostics in unreachable code#24070
sharkdp merged 2 commits intomainfrom
david/reveal_type-unreachable

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Mar 20, 2026

Summary

In unreachable sections of code, we infer Never for symbols that were define outside the unreachable part. This means, that we infer Never for the reveal_type symbol here:

from typing import reveal_type

if False:
    reveal_type(1)  # no diagnostic! `reveal_type` is inferred as `Never`

This PR fixes that by explicitly detecting callables named reveal_type that have a type of Never. I'm sure there ways to make this more bullet-proof, but it seems very unlikely that this will cause "false positives".

I'm not sure if we should do something similar assert_type/assert_never, but it seems to me like those are different. Instead of just revealing a potentially surprising type in unreachable code, those could accidentally look like they succeed when they shouldn't, or they could fail when they should appear to succeed.

Test Plan

New Markdown tests.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Mar 20, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 20, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 85.29%. The percentage of expected errors that received a diagnostic held steady at 78.13%. The number of fully passing files held steady at 64/132.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 20, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 20, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
invalid-return-type 0 1 0
Total 0 41 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. I do think we need to do something about assert_type diagnostics in unreachable code -- see #24024 (comment) -- but we can discuss that separately

@sharkdp sharkdp merged commit b8805a1 into main Mar 20, 2026
48 checks passed
@sharkdp sharkdp deleted the david/reveal_type-unreachable branch March 20, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants