Revert PEP 604 union syntax to Union[]/Optional[] for Python 3.9 compatibility#1228
Merged
Revert PEP 604 union syntax to Union[]/Optional[] for Python 3.9 compatibility#1228
Conversation
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
…bility - Add Union and Optional imports from typing module - Convert X | None to Optional[X] - Convert X | Y to Union[X, Y] - Keep imports sorted alphabetically - Maintain __future__ annotations import Co-authored-by: bact <128572+bact@users.noreply.github.com>
…compatibility Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Revert PEP 604 union types to Union[] for Python 3.9 support
Revert PEP 604 union syntax to Union[]/Optional[] for Python 3.9 compatibility
Jan 26, 2026
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
This reverts commit 62ff5c8.
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What does this changes
Converts all PEP 604 union type syntax (
X | Y) to traditionalUnion[X, Y]andOptional[X]across 46 files.What was wrong
PEP 604 syntax (
str | None,list[str] | str) requires Python 3.10+. Whilefrom __future__ import annotationsallows the syntax to parse in 3.9, it stores annotations as strings and can cause runtime failures in type checking or introspection. The project'srequires-python = ">=3.9"demands full compatibility.How this fixes it
X | None→Optional[X]X | Y→Union[X, Y]X | Y | Z→Union[X, Y, Z]Added typing imports (
Union,Optional) to affected modules, merged with existing imports alphabetically. Preservedfrom __future__ import annotationsfor forward compatibility.Example transformation:
Affected modules: tokenize, parse, translate, spell, summarize, tag, transliterate, util, corpus, and 10+ others.
Your checklist for this pull request
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.