Skip to content

Conformance: broaden enum-expansion tests - #2324

Merged
davidhalter merged 2 commits into
python:mainfrom
tapetersen:enums-expansion-full-union-assignability
Aug 4, 2026
Merged

Conformance: broaden enum-expansion tests#2324
davidhalter merged 2 commits into
python:mainfrom
tapetersen:enums-expansion-full-union-assignability

Conversation

@tapetersen

Copy link
Copy Markdown
Contributor

The spec's Enum Literal Expansion section states that a type checker
should treat a complete union of all literal members as equivalent to
the enum type. Add test to cover cases failing in some checkers.

Also refreshes all three quoted spec passages, which had drifted from
the section as rewritten in a6eeccf ("new type system concepts section",

Fixes #2323.

@python-cla-bot

python-cla-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@tapetersen
tapetersen force-pushed the enums-expansion-full-union-assignability branch from 36acade to 43b2427 Compare July 30, 2026 12:31
@srittau srittau added the topic: conformance tests Issues with the conformance test suite label Jul 30, 2026

@carljm carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs rebasing, but LGTM

The spec's Enum Literal Expansion section states that a type checker
should treat a complete union of all literal members as equivalent to
the enum type. Add test to cover cases failing in some checkers.

Also refreshes all three quoted spec passages, which had drifted from
the section as rewritten in a6eeccf ("new type system concepts section",

Reported in python#2323.
Four checkers accept the full-literal-union equivalency and are
unaffected: mypy, pyrefly, pycroscope and ty (mypy and ty remain
"Partial" for the pre-existing `Flag` narrowing gap only). Three drop
from "Pass" to "Partial":

* pyright and zuban reject both the assignment and the `assert_type`.
* basilisk rejects only the assignment; it reports the `assert_type` in
  test1 as redundant, so it does treat the two types as equivalent
  there.
@tapetersen
tapetersen force-pushed the enums-expansion-full-union-assignability branch from 43b2427 to 5a0263b Compare August 4, 2026 09:13
@tapetersen

Copy link
Copy Markdown
Contributor Author

@carljm Rebased on main and thanks.

@davidhalter

Copy link
Copy Markdown
Collaborator

I fixed this in Zuban as well, merging now, updating the tests later.

@davidhalter
davidhalter merged commit a490662 into python:main Aug 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: conformance tests Issues with the conformance test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enums_expansion.py test3 misses cases of the union-of-all-member = enum equivalency

5 participants