refactor: avoid having "Any" expressions#181
Merged
Merged
Conversation
Collaborator
Author
|
note: will squash commits |
Contributor
There was a problem hiding this comment.
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_exprinpyproject.tomland update code/tests to satisfy the stricter typing rules. - Introduce a
TypeGuardcompatibility export in_compat.pyand useTypeGuardin API-shape validators (api_types.py), allowing removal of downstreamcast(...)usage. - Refactor several areas (CLI argument typing, server response handling, manifest parsing, tests) to avoid
Anyand 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.
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.
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
disallow_any_exprin themypyconfiguration.TypeGuardwhen appropriate (and so, add theTypeguardimport in_compat.py.Screenshots (if appropriate):
Not approriate.
How has this been tested?
Applied local tests.
Resources
Not approriate.
Types of changes
Checklist