Skip to content

fix(match): change match creation behavior to be multi-thread compliant - #213

Merged
mdevolde merged 1 commit into
jxmorris12:masterfrom
mdevolde:fix/multi_thread_match
Jul 1, 2026
Merged

fix(match): change match creation behavior to be multi-thread compliant#213
mdevolde merged 1 commit into
jxmorris12:masterfrom
mdevolde:fix/multi_thread_match

Conversation

@mdevolde

@mdevolde mdevolde commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

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

  • Make language_tool_python.Match.four_byte_char_positions public.
  • language_tool_python.match.Match.__init__ now takes a four_byte_positions argument instead of text.
  • Remove the Match.PREVIOUS_MATCHES_TEXT and Match.FOUR_BYTES_POSITIONS class attributes (using insteead four_byte_positions arg).
  • In language_tool_python.server.LanguageTool.check, create Match with this new signature.

Screenshots (if appropriate):

Not applicable.

How has this been tested?

Applied local tests.

Resources

Not applicable.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation only)
  • Refactor / code style update (non-breaking change that improves code structure or readability)
  • Tests / CI improvement (adding or updating tests or CI configuration only)
  • Chore / maintenance (non-breaking change that does not affect functionality, such as updating dependencies or fixing typos)
  • Other (please describe):

Checklist

  • Followed the project's contributing guidelines.
  • Updated any relevant tests.
  • Updated any relevant documentation.
  • Added comments to your code where necessary.
  • Formatted your code, run the linters, checked types and tests.
  • Added your changes to the CHANGELOG file, if applicable.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in LanguageTool.check().
  • Refactors Match.__init__ to accept precomputed four_byte_positions instead of the original text, removing the previous class-level cache.
  • Updates CHANGELOG.md to 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.

Comment thread src/language_tool_python/server.py
Comment thread src/language_tool_python/match.py Outdated
Comment thread CHANGELOG.md Outdated
@codecov-commenter

codecov-commenter commented Jul 1, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.67%. Comparing base (3ebb352) to head (a03e122).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mdevolde
mdevolde force-pushed the fix/multi_thread_match branch from 16e2eab to 918d307 Compare July 1, 2026 14:38
@mdevolde
mdevolde force-pushed the fix/multi_thread_match branch from 918d307 to a03e122 Compare July 1, 2026 14:38
@mdevolde
mdevolde merged commit c13dbb5 into jxmorris12:master Jul 1, 2026
13 checks passed
@mdevolde
mdevolde deleted the fix/multi_thread_match branch July 1, 2026 15:04
mdevolde added a commit to mdevolde/language_tool_python that referenced this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants