Complete type annotations: 100% functions, 56.56% variables, eliminate 25+ Any types - #1272
Merged
Merged
Conversation
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
…dules Co-authored-by: bact <128572+bact@users.noreply.github.com>
…anslate modules Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add type hints to submodules for 100% coverage
Add type hints incrementally to reach 87.78% coverage
Feb 3, 2026
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>
…ert, soundex modules 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>
bact
marked this pull request as ready for review
February 3, 2026 16:43
…m_onnx 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>
- pythainlp/ulmfit/core.py: merge_wgts - pythainlp/tokenize/multi_cut.py: serialize, LatticeString.__new__ - pythainlp/ulmfit/tokenizer.py: ThaiTokenizer.add_special_cases - pythainlp/phayathaibert/core.py: ThaiTextProcessor._replace_rep - pythainlp/ulmfit/preprocess.py: _replace_rep (2 functions) - pythainlp/util/normalize.py: _last_char - pythainlp/wangchanberta/core.py: _get_tokenizer, ThaiNameTagger._clear_tag, ThaiNameTagger._IOB, NamedEntityRecognition._fix_span_error - pythainlp/coref/_fastcoref.py: FastCoref._to_json - pythainlp/tokenize/budoux.py: _init_parser - pythainlp/tokenize/etcc.py: _cut_etcc - pythainlp/tokenize/nlpo3.py: _ensure_default_dict_loaded - pythainlp/khavee/core.py: KhaveeVerifier.check_karu_lahu All functions now have complete parameter and return type hints using Python 3.9+ compatible syntax (Union[], Optional[], not |). Co-authored-by: bact <128572+bact@users.noreply.github.com>
All 720 functions now have complete type hints. Updated CSV and JSON files reflect zero functions with missing or incomplete type hints. Co-authored-by: bact <128572+bact@users.noreply.github.com>
Added type annotations to ~50+ more module-level variables: - All __all__ lists in __init__.py files typed as list[str] - Translation/transliteration modules - Tag modules (orchid, blackboard) - Morpheme, augment, chat, classify, tools modules Co-authored-by: bact <128572+bact@users.noreply.github.com>
Added type annotations to utility module variables: - pythainlp/util/morse.py: 4 variables - pythainlp/util/emojiconv.py: 1 variable - pythainlp/util/wordtonum.py: 6 variables All Pattern[str] properly annotated for regex patterns Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Added instance variable annotations in __init__ methods for: * pythainlp/generate/core.py: Unigram, Bigram, Trigram classes (20 vars) * pythainlp/transliterate/w2p.py: Thai_W2P class (20 vars) * pythainlp/translate/tokenization_small100.py: SMALL100Tokenizer (14 vars) * pythainlp/augment/wordnet.py: WordNetAug class (12 vars) * pythainlp/transliterate/thai2rom.py: ThaiTransliterator, Encoder, etc. (12 vars) * pythainlp/tag/_tag_perceptron.py: AveragedPerceptron, PerceptronTagger (11 vars) * pythainlp/transliterate/thaig2p.py: ThaiG2P, Encoder, Decoder, etc. (11 vars) * pythainlp/wangchanberta/core.py: ThaiNameTagger, NamedEntityRecognition (11 vars) * pythainlp/generate/wangchanglm.py: WangChanGLM class (10 vars) * pythainlp/word_vector/core.py: WordVector class (3 vars) * pythainlp/tag/named_entity.py: NER, NNER classes (4 vars) * pythainlp/transliterate/thaig2p_v2.py: ThaiG2P class (1 var) * pythainlp/transliterate/thai2rom_onnx.py: Seq2Seq_ONNX class (7 vars) * pythainlp/summarize/freq.py: FrequencySummarizer class (4 vars) * pythainlp/tokenize/multi_cut.py: LatticeString class (3 vars) * pythainlp/ulmfit/tokenizer.py: BaseTokenizer, ThaiTokenizer (2 vars) * pythainlp/tag/crfchunk.py: CRFchunk class (3 vars) Total: ~150+ instance variable annotations added Co-authored-by: bact <128572+bact@users.noreply.github.com>
- Added instance variable annotations in __init__ methods for: * pythainlp/augment/lm/fasttext.py: FastTextAug class (3 vars) * pythainlp/augment/word2vec/core.py: Word2VecAug class (3 vars) * pythainlp/tag/thainer.py: ThaiNameTagger class (2 vars) * pythainlp/spell/words_spelling_correction.py: FastTextEncoder class (12 vars) Total: ~20+ instance variable annotations added in this batch Cumulative: ~170+ annotations added across all batches Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
…variables Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
🎉 Complete class attribute type annotations - 100% coverage achieved across entire codebase
Complete type annotations: 100% functions, 56.56% variables (+21.46pp)
Feb 3, 2026
…e spaCy and fastcoref types Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
Complete type annotations: 100% functions, 56.56% variables (+21.46pp)
Complete type annotations: 100% functions, 100% class attributes, 56.56% variables with precise library types
Feb 3, 2026
…l and PreTrainedTokenizerBase Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot
AI
changed the title
Complete type annotations: 100% functions, 100% class attributes, 56.56% variables with precise library types
Complete type annotations: 100% functions, 56.56% variables, replace Any with precise library types
Feb 3, 2026
…ules Co-authored-by: bact <128572+bact@users.noreply.github.com>
…ch 2 Co-authored-by: bact <128572+bact@users.noreply.github.com>
|
Copilot
AI
changed the title
Complete type annotations: 100% functions, 56.56% variables, replace Any with precise library types
Complete type annotations: 100% functions, 56.56% variables, eliminate 25+ Any types
Feb 4, 2026
bact
approved these changes
Feb 4, 2026
32 tasks
Copilot stopped work on behalf of
bact due to an error
February 4, 2026 09:02
This was referenced Feb 4, 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
Systematically improves type coverage across the codebase:
Anytypes with library-specific types by investigating external source codeKey improvements:
Anywith actual types from transformers, spacy, gensim, numpy, onnxruntime, sentencepieceExample transformations:
Files with major improvements:
wangchanberta/core.py: CamembertTokenizer, TokenClassificationPipelinecoref/_fastcoref.py: Language, CorefModelspell/words_spelling_correction.py: NDArray types, InferenceSessionaugment/lm/fasttext.py: FastText, KeyedVectorstranslate/tokenization_small100.py: SentencePieceProcessorWhat was wrong
Type annotations were incomplete:
Anyinstead of precise library typesHow this fixes it
Variable annotations: Added 251 annotations to module constants, instance variables, and class attributes across 60+ files using proper types (dict[str, str], Pattern[str], etc.).
Precise types: Investigated external library source code (transformers, spacy, fastcoref, gensim, etc.) to replace
Anywith actual types. Used TYPE_CHECKING guards to avoid runtime overhead.Dev branch integration: Merged latest dev changes (ThaiNNER refactoring) while maintaining type improvements.
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.