Skip to content

refactor: avoid having "Any" expressions#181

Merged
mdevolde merged 16 commits into
jxmorris12:masterfrom
mdevolde:refactor/mypy
Jun 11, 2026
Merged

refactor: avoid having "Any" expressions#181
mdevolde merged 16 commits into
jxmorris12:masterfrom
mdevolde:refactor/mypy

Conversation

@mdevolde

@mdevolde mdevolde commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

refactor: avoid having "Any" expressions

Why the pull request was made

To avoid having any expressions, and ensuring a more accurate typing in the library.

Summary of changes

  • Activate a new rule disallow_any_expr in the mypy configuration.
  • Patch new warnings raised by this rule.
  • Use TypeGuard when appropriate (and so, add the Typeguard import in _compat.py.

Screenshots (if appropriate):

Not approriate.

How has this been tested?

Applied local tests.

Resources

Not approriate.

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)
  • 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.

@mdevolde

Copy link
Copy Markdown
Collaborator Author

note: will squash commits

@mdevolde mdevolde self-assigned this Jun 11, 2026

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 tightens type-safety across language_tool_python by enabling mypy’s disallow_any_expr and refactoring code/tests to remove (or better constrain) Any-typed expressions, including introducing TypeGuard compatibility helpers.

Changes:

  • Enable disallow_any_expr in pyproject.toml and update code/tests to satisfy the stricter typing rules.
  • Introduce a TypeGuard compatibility export in _compat.py and use TypeGuard in API-shape validators (api_types.py), allowing removal of downstream cast(...) usage.
  • Refactor several areas (CLI argument typing, server response handling, manifest parsing, tests) to avoid Any and improve typed interfaces.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_safe_zip.py Adjusts reload usage to avoid retaining reloaded module in a way that can introduce typing issues.
tests/test_match.py Replaces loosely-typed dict expectations with a TypedDict and explicit field assertions.
tests/test_download.py Replaces MagicMock patterns with lightweight typed helpers; patches datetime and Java compatibility checks in a typed way.
tests/test_deprecated.py Adds explicit result annotations to satisfy stricter typing.
pyproject.toml Enables mypy disallow_any_expr and updates dependency comments for typing_extensions.
language_tool_python/utils.py Removes Windows-specific startupinfo helper from utils; refactors JAR dir resolution to avoid ambiguous typing.
language_tool_python/server.py Replaces casts with TypeGuard-based narrowing; refactors sorting and error decoding helpers; Windows startupinfo setup moved here.
language_tool_python/match.py Introduces a MatchValue alias and refactors ordered representation/iteration to be more precisely typed.
language_tool_python/language_tag.py Avoids Any-adjacent regex group access patterns by slicing via match spans.
language_tool_python/download_lt.py Adds typed TOML manifest loading/validation helpers and avoids Any from direct TOML parsing.
language_tool_python/config_file.py Refactors config schema typing to avoid generics/Any pitfalls while keeping runtime checks.
language_tool_python/api_types.py Converts response validators to return TypeGuard[...] for proper type narrowing.
language_tool_python/_compat.py Adds TypeGuard export with version-conditional import.
language_tool_python/main.py Introduces typed CLI args namespace and typed helpers for TOML loading/version reading; removes some Any-driven casts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread language_tool_python/download_lt.py
@mdevolde mdevolde merged commit 40897f1 into jxmorris12:master Jun 11, 2026
10 checks passed
@mdevolde mdevolde deleted the refactor/mypy branch June 11, 2026 10:19
@mdevolde mdevolde mentioned this pull request Jun 11, 2026
12 tasks
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.

2 participants