Tidy exception forwarding, warning consistency, and document conventions#1355
Merged
Tidy exception forwarding, warning consistency, and document conventions#1355
Conversation
…onventions to CONTRIBUTING.md Co-authored-by: bact <128572+bact@users.noreply.github.com> Agent-Logs-Url: https://github.com/PyThaiNLP/pythainlp/sessions/1a240bb9-52d0-40e6-8739-79cf52fa9e65
Copilot
AI
changed the title
[WIP] Tidy code for consistency, predictability, and scriptability
Tidy exception forwarding, warning consistency, and document conventions
Mar 22, 2026
|
bact
approved these changes
Mar 22, 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.



18
raisestatements insideexceptblocks were missingfromchaining, silently discarding original tracebacks. Three warning calls omitted thecategoryargument and used inconsistent messages for the same condition. No documented convention existed for either.Exception forwarding (chaining)
Every
except ImportError/ModuleNotFoundError:that re-raised was updated to capture the original and chain it:raise eintools/misspell.py→ bareraise(preserves original traceback; unusedas eremoved).raise ValueError(str(e))incorpus/core.py→raise ValueError(str(e)) from e.Files:
cli/benchmark.py,corpus/core.py,parse/{esupar,attaparse}_engine.py,spell/{symspellpy,phunspell,tltk}.py,tag/{tltk,pos_tag,thai_nner}.py,tokenize/{deepcut,tltk}.py,tools/misspell.py,translate/en_th.py,transliterate/tltk.py,util/abbreviation.pyWarning consistency
Three
warnings.warncalls inphayathaibert/core.pyandwangchanberta/core.py(two locations) had no explicitcategoryand used three different phrasings for the same condition. All normalized to:ImportError message normalization
All ImportError messages updated to the canonical form established by the new convention:
CONTRIBUTING.md — new section: "Error messages, warnings, and exception handling"
Added under Code Guidelines to codify the conventions above for contributors and AI agents:
from evs.from Nonevs. bareraise), with correct/incorrect examplescategory+stacklevel, recommended categories table, message style)Your checklist for this pull request
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.