Skip to content

Fix match statement narrowing for self-matching class patterns with literal arguments - #21918

Merged
hauntsaninja merged 1 commit into
python:masterfrom
EmmanuelNiyonshuti:fix-21780
Sep 1, 2026
Merged

Fix match statement narrowing for self-matching class patterns with literal arguments#21918
hauntsaninja merged 1 commit into
python:masterfrom
EmmanuelNiyonshuti:fix-21780

Conversation

@EmmanuelNiyonshuti

Copy link
Copy Markdown
Contributor

Fixes #21780

This was likely because join_types was being used to combine two possible remaining types (e.g. tuple[int, int] and int), and it would collapse those into object instead of keeping both, which is why mypy couldn't narrow down to a bottom type (Never).

This PR replaces join_types with make_simplified_union, and adds a regression test based on the repro in the issue.

Could be a better fix than this, I would welcome it.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@hauntsaninja
hauntsaninja merged commit 3ad6157 into python:master Sep 1, 2026
25 checks passed
@EmmanuelNiyonshuti
EmmanuelNiyonshuti deleted the fix-21780 branch September 1, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

match does not infer never with None followed by Literal

2 participants