Revert union type syntax from | to Union[] for Python 3.9 runtime compatibility#1230
Merged
Revert union type syntax from | to Union[] for Python 3.9 runtime compatibility#1230
| to Union[] for Python 3.9 runtime compatibility#1230Conversation
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
…tations Co-authored-by: bact <128572+bact@users.noreply.github.com>
…arameters Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wrong and inconsistent type hints in Pythainlp
Fix type hint inconsistencies across tokenize, corpus, util, tools, and tag modules
Jan 29, 2026
…typing.get_type_hints() Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
Fix type hint inconsistencies across tokenize, corpus, util, tools, and tag modules
Revert union type syntax from Jan 29, 2026
| to Union[] for Python 3.9 runtime compatibility
|
bact
approved these changes
Jan 29, 2026
This was referenced Jan 29, 2026
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
Replaces all
A | Bunion type syntax withUnion[A, B]andOptional[A]in type hints across 8 files incorpus,tools,util, andtagmodules.What was wrong
The
|union syntax fails at runtime in Python 3.9 when introspection tools calltyping.get_type_hints(), despitefrom __future__ import annotationsallowing it to parse. This breaks static analysis tools, documentation generators, and runtime type inspection.How this fixes it
Union[frozenset[str], list[dict[str, str]]]Optional[_ResponseWrapper]Optional[tuple[...]],Optional[list[str]]Optional[int]Optional[list[list[str]]]tuple[bool, Optional[str]]Union[str, list[tuple[str, str]]]Union[str, bool],Optional[type[BaseException]],Optional[types.TracebackType]Added necessary
UnionandOptionalimports where missing.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.