Skip to content

Handle PEP 604 unions inside type annotations - #592

Open
vitalivo wants to merge 1 commit into
agronholm:masterfrom
vitalivo:fix/pep604-class-unions
Open

vitalivo wants to merge 1 commit into
agronholm:masterfrom
vitalivo:fix/pep604-class-unions

Conversation

@vitalivo

Copy link
Copy Markdown

Changes

Use the union checker for PEP 604 unions inside type[...], as already done for typing.Union.

For example, check_type(list, type[str | Any]) currently raises TypeCheckError, even though Any permits the class. Invalid classes also lose the per-member diagnostics. The regression tests cover both positions of Any, accepted classes, and rejection messages for both union spellings.

Validation

  • Python 3.12: 540 passed, 9 skipped, 9 xfailed.
  • Three regression cases fail with the original checker.
  • Ruff 0.15.20 lint and formatting checks pass for both changed Python files.
  • Mypy 2.1.0 reports the same existing missing typeshed.stdlib.types import in _decorators.py:22 on the base commit and this patch.

Checklist

  • Added tests that fail without the patch.
  • Added a changelog entry.
  • Documentation: no new API or syntax; this fixes support for the existing union syntax.

@vitalivo
vitalivo force-pushed the fix/pep604-class-unions branch from 469237e to 97ef4ea Compare September 13, 2026 16:23
@coveralls

coveralls commented Sep 13, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 94.853%. remained the same — vitalivo:fix/pep604-class-unions into agronholm:master

This branch has not been deployed

No deployments
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.

2 participants