fix(match): change match creation behavior to be multi-thread compliant - #213
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates how Match objects are constructed to avoid shared mutable class-level state, making offset adjustment for 4-byte UTF-8 characters safe under concurrent .check() calls.
Changes:
- Exposes
four_byte_char_positions()publicly and reuses it inLanguageTool.check(). - Refactors
Match.__init__to accept precomputedfour_byte_positionsinstead of the originaltext, removing the previous class-level cache. - Updates
CHANGELOG.mdto document the new public helper and the breaking constructor change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/language_tool_python/server.py | Precomputes 4-byte char positions once per .check() call and passes them into Match. |
| src/language_tool_python/match.py | Makes 4-byte char position helper public and changes Match construction to avoid shared class state. |
| CHANGELOG.md | Documents the new public helper, the breaking API change, and the concurrency bug fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #213 +/- ##
==========================================
+ Coverage 80.66% 80.67% +0.01%
==========================================
Files 13 13
Lines 1769 1770 +1
==========================================
+ Hits 1427 1428 +1
Misses 342 342 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
16e2eab to
918d307
Compare
918d307 to
a03e122
Compare
fix(match): change match creation behavior to be multi-thread compliant
Why the pull request was made
To ensure having a multi-thread compliant lib.
Summary of changes
language_tool_python.Match.four_byte_char_positionspublic.language_tool_python.match.Match.__init__now takes afour_byte_positionsargument instead oftext.Match.PREVIOUS_MATCHES_TEXTandMatch.FOUR_BYTES_POSITIONSclass attributes (using insteeadfour_byte_positionsarg).language_tool_python.server.LanguageTool.check, createMatchwith this new signature.Screenshots (if appropriate):
Not applicable.
How has this been tested?
Applied local tests.
Resources
Not applicable.
Types of changes
Checklist