Skip to content

Enable ruff TC rules (type-checking imports)#1999

Closed
iMicknl wants to merge 4 commits intov2/mainfrom
v2/ruff-tc
Closed

Enable ruff TC rules (type-checking imports)#1999
iMicknl wants to merge 4 commits intov2/mainfrom
v2/ruff-tc

Conversation

@iMicknl
Copy link
Copy Markdown
Owner

@iMicknl iMicknl commented Apr 19, 2026

Summary

  • Move type-only imports into TYPE_CHECKING blocks across 13 files
  • Quote type expressions in cast() calls
  • Reduces runtime import overhead without changing behavior

Test plan

  • ruff check . passes
  • pytest — 280 tests pass
  • mypy passes

Copilot AI review requested due to automatic review settings April 19, 2026 17:21
@iMicknl iMicknl requested a review from tetienne as a code owner April 19, 2026 17:21
@iMicknl iMicknl added enhancement New feature or request v2 labels Apr 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 TC rules in pyproject.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.

@iMicknl iMicknl force-pushed the v2/ruff-tc branch 3 times, most recently from c63e733 to 33d0ee5 Compare April 19, 2026 18:27
@iMicknl
Copy link
Copy Markdown
Owner Author

iMicknl commented Apr 21, 2026

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

@copilot resolve the merge conflicts in this pull request

Resolved. I merged v2/main into this branch and fixed the conflicts in pyoverkiz/models.py while preserving the existing type-safety checks. Included in commit 0720d90 (merge conflict resolution commit: 261049b).

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:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Collaborator

@tetienne tetienne left a comment

Choose a reason for hiding this comment

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

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.

Comment thread pyoverkiz/models.py Outdated
Comment thread pyoverkiz/models.py Outdated
Comment thread pyproject.toml
- 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
iMicknl added 3 commits April 24, 2026 13:08
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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 TC rules in pyproject.toml (with TC006 ignored).
  • 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.

Comment thread pyoverkiz/models.py
Comment on lines +26 to +28
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
@iMicknl
Copy link
Copy Markdown
Owner Author

iMicknl commented Apr 24, 2026

@tetienne this conflicts quite a bit with the cattr changes, and the benefit is not too much. I will close this.

@iMicknl iMicknl closed this Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants