Enable ruff TC rules (type-checking imports)#1999
Conversation
There was a problem hiding this comment.
Pull request overview
Enables Ruff’s flake8-type-checking (“TC”) rules and updates the codebase to comply by moving type-only imports behind TYPE_CHECKING guards and avoiding runtime-evaluated type references (notably in cast() calls), reducing import-time overhead.
Changes:
- Enable Ruff
TCrules inpyproject.toml. - Move type-only imports into
if TYPE_CHECKING:blocks across the codebase. - Quote type expressions in
cast()calls to avoid runtime type dependencies.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| utils/generate_enums.py | Move model imports to TYPE_CHECKING and quote cast() type expressions. |
| pyproject.toml | Enable Ruff TC rules. |
| pyoverkiz/types.py | Guard Callable import behind TYPE_CHECKING. |
| pyoverkiz/response_handler.py | Guard aiohttp.ClientResponse import behind TYPE_CHECKING. |
| pyoverkiz/obfuscate.py | Guard JSON type import behind TYPE_CHECKING. |
| pyoverkiz/models.py | Guard typing-only imports and quote cast() type expressions. |
| pyoverkiz/enums/base.py | Quote cast() type argument for Self. |
| pyoverkiz/client.py | Guard typing-only imports and quote cast() type expressions. |
| pyoverkiz/auth/strategies.py | Guard typing-only imports and quote cast() type expressions. |
| pyoverkiz/auth/factory.py | Guard typing-only imports (ssl, ClientSession, ServerConfig). |
| pyoverkiz/auth/base.py | Guard Mapping import behind TYPE_CHECKING. |
| pyoverkiz/action_queue.py | Guard typing-only imports behind TYPE_CHECKING. |
| pyoverkiz/_case.py | Guard Callable import behind TYPE_CHECKING. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c63e733 to
33d0ee5
Compare
|
@copilot resolve the merge conflicts in this pull request |
Resolved. I merged Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
tetienne
left a comment
There was a problem hiding this comment.
The TYPE_CHECKING moves are all safe — I traced each one and every symbol is used only in annotation contexts, so no runtime impact. And the full_jitter + max_time additions in the earlier commits are a nice improvement. Two things caught my eye that are worth fixing before this merges though.
- Move type-only imports behind TYPE_CHECKING guards across 13 files - Ignore TC006 (quoting cast types hurts IDE autocomplete) - Reduces import-time overhead by deferring annotation-only imports
Unquote all cast("Type", ...) back to cast(Type, ...) to restore
IDE autocomplete and click-through. TC006 remains ignored to prevent
ruff from re-quoting. Also fix remaining TC001 and ty check issues.
OverkizCommand, OverkizCommandParam, APIType, and Server are used in attrs @define field annotations that cattrs resolves at runtime via typing.get_type_hints(). Moving them to TYPE_CHECKING caused NameError during structuring. Restore as runtime imports with noqa: TC001.
There was a problem hiding this comment.
Pull request overview
Enables Ruff’s flake8-type-checking (TC) rules and adjusts imports across the codebase to ensure type-only dependencies don’t add runtime import cost, while keeping runtime behavior unchanged.
Changes:
- Enable Ruff
TCrules inpyproject.toml(withTC006ignored). - Move type-only imports under
if TYPE_CHECKING:blocks across multiple modules. - Remove redundant
cast()usage in the enum generation script and add targeted type-checker ignores where needed.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| utils/generate_enums.py | Moves model imports behind TYPE_CHECKING and removes unnecessary cast() calls for reference endpoints. |
| pyproject.toml | Enables Ruff TC rules and ignores TC006. |
| pyoverkiz/types.py | Moves Callable import behind TYPE_CHECKING for type-only usage. |
| pyoverkiz/response_handler.py | Moves aiohttp.ClientResponse import behind TYPE_CHECKING. |
| pyoverkiz/obfuscate.py | Moves JSON type import behind TYPE_CHECKING. |
| pyoverkiz/models.py | Moves Iterator behind TYPE_CHECKING and adds TC suppressions for selected imports. |
| pyoverkiz/enums/base.py | Adds ty inline ignore on UNKNOWN fallback cast. |
| pyoverkiz/client.py | Moves several type-only imports (e.g., Details, TracebackType, JSON) behind TYPE_CHECKING. |
| pyoverkiz/auth/strategies.py | Moves Mapping, SSLContext, and credential/config imports behind TYPE_CHECKING; updates annotations accordingly. |
| pyoverkiz/auth/factory.py | Moves SSLContext, ClientSession, and ServerConfig imports behind TYPE_CHECKING; updates annotations accordingly. |
| pyoverkiz/auth/base.py | Moves Mapping import behind TYPE_CHECKING. |
| pyoverkiz/action_queue.py | Moves Callable/Coroutine/Generator and ExecutionMode imports behind TYPE_CHECKING. |
| pyoverkiz/_case.py | Moves Callable import behind TYPE_CHECKING. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from pyoverkiz.enums.command import OverkizCommand, OverkizCommandParam # noqa: TC001 | ||
| from pyoverkiz.enums.protocol import Protocol | ||
| from pyoverkiz.enums.server import APIType, Server | ||
| from pyoverkiz.enums.server import APIType, Server # noqa: TC001 |
|
@tetienne this conflicts quite a bit with the |
Summary
TYPE_CHECKINGblocks across 13 filescast()callsTest plan
ruff check .passespytest— 280 tests passmypypasses