Verify and fix type hints, annotations, and docstrings - #1268
Merged
Conversation
- Fixed translate/core.py to properly type the model Union - Fixed zh_th.py, th_fr.py, small100.py to return str properly - Fixed tokenization_small100.py prefix_tokens to Optional[list[int]] - Fixed en_th.py, word2word_translate.py with type ignore comments - Fixed transliterate files (umt5_thaig2p, thaig2p_v2, w2p) - Reduced mypy errors from 84 to 67 Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Fixed summarize/core.py - added cast for sent_tokenize, fixed stop_words type narrowing - Fixed summarize/freq.py - added cast for sent_tokenize - Fixed summarize/keybert.py - added type ignore for numpy operations - Added return type annotation for rank_by_frequency - Reduced mypy errors from 67 to 56 Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Fixed type annotations for decoded_list in translate files (zh_th, th_fr, small100) - Removed unused type ignore comments in tokenization_small100.py - Fixed parse modules to use Optional[str] for model parameters - Fixed coref/core.py to accept Union[str, list[str]] for texts parameter - Reduced mypy errors from 56 to 46 Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Added Optional import to parse/esupar_engine.py - Fixed tokenization_small100.py type ignore comments - Added type ignore for external library calls in el/core.py and chat/core.py - Fixed parse/core.py type ignore comment error code - Reduced mypy errors from 46 to 40 Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Fixed all remaining 40 mypy errors (100% success - 0 errors!) - Added proper type annotations throughout the codebase - Fixed import issues in parse and tag modules - Updated pyproject.toml to ignore ufal module imports - Applied ruff formatting to all files - All type hints now properly verified Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Fixed wordnet.py to use the tokenize parameter as intended - Fixed thai2fit and ltw2v to properly handle None corpus paths with clear error messages - Fixed tokenization_small100.py type ignore comment formatting - All mypy checks still passing (0 errors) Co-authored-by: bact <128572+bact@users.noreply.github.com>
|
bact
marked this pull request as ready for review
February 3, 2026 11:48
Copilot
AI
changed the title
[WIP] Verify type hints, annotations, and docstrings
Verify and fix type hints, annotations, and docstrings
Feb 3, 2026
bact
approved these changes
Feb 3, 2026
This was referenced Feb 3, 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 do these changes do
Eliminates all 84 mypy type checking errors across 191 source files and ensures type hints match docstrings throughout the codebase.
What was wrong
Recent PRs (#1262-#1267) added type hints that contained errors:
Anyinstead of declared types (38 instances)None(14 instances)Optional[str]needed whereNonewas possiblepos_tag)List[str]vslist[str], missingUnion[]wrapperHow this fixes it
Core type system fixes:
Uniontypes for polymorphic model classes (translate/core.py)Optional[str]whereNonechecks existedTYPE_CHECKINGimports to prevent circular dependenciesExternal library boundaries:
# type: ignore[no-any-return]for untyped external calls (transformers, numpy, fairseq)NoneImport organization:
pos_tagcollision:from pythainlp.tag.pos_tag import pos_tagufalimports to function scope for lazy loadingufal.*to mypy ignore list in pyproject.tomlType narrowing:
cast()forsent_tokenizethat returnsUnion[list[str], list[list[str]]]based on input typeNonechecks before passing to non-optional parametersStandards compliance:
list,dict) instead ofList,Dictfor Python 3.9+Union[A, B]instead ofA | Bfor compatibilityYour checklist for this pull request
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.