Add type hints to modules in extra test suite - #1267
Merged
Conversation
…appers Fixed type hints for modules used in extra test suite: - pythainlp.corpus.wordnet: All functions now have proper type ignore annotations - pythainlp.spell.tltk and phunspell: Added type ignore for external library returns - pythainlp.transliterate.tltk and ipa: Fixed transliteration functions - pythainlp.tag.tltk: Fixed pos_tag function - pythainlp.word_vector.core: Fixed all no-any-return errors Analyzed NLTK wordnet source to verify return types are correct. Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Added explicit np.intp type annotations for numpy sum operations - Fixed _binary_representation to properly annotate bin_rept as np.ndarray - Added type ignore for bpemb and wangchanberta external library returns - All tests in benchmarks and augment modules pass Co-authored-by: bact <128572+bact@users.noreply.github.com>
|
Copilot
AI
changed the title
[WIP] Add type hints to submodules incrementally
Add type hints to modules in extra test suite
Feb 3, 2026
bact
approved these changes
Feb 3, 2026
bact
marked this pull request as ready for review
February 3, 2026 11:12
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
Adds complete type annotations to 8 modules tested in the "extra" test suite:
corpus.wordnet,spell.{tltk,phunspell},word_vector.core,transliterate.{tltk,ipa},tag.tltk,augment.word2vec.bpemb_wv,augment.lm.wangchanberta, andbenchmarks.word_tokenization.What was wrong
Functions lacked type hints, causing mypy errors and poor IDE support. External libraries (NLTK, tltk, epitran, phunspell, bpemb) return
Anywithout type stubs.How this fixes it
Approach:
synsets()returnslist,langs()returnslist)# type: ignore[no-any-return]only when external libraries genuinely lack type stubsnp.intp,np.ndarray) in benchmarks module instead of generic annotationsKey changes:
wordnet.py: Added type ignores to 10 wrapper functions after verifying NLTK sourcebenchmarks/word_tokenization.py: Explicitnp.intpannotations for sum operations,np.ndarrayfor binary representationspell/,transliterate/,tag/,augment/: Type ignores for external library returnsExample:
Your checklist for this pull request
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.