Skip to content

Commit c63e733

Browse files
committed
Enable ruff TC rules and move type-only imports to TYPE_CHECKING blocks
Move imports only used for type annotations into TYPE_CHECKING blocks. Ignore TC006 (quoting cast types) as it hurts IDE autocomplete with no measurable import-time benefit.
1 parent efa3be4 commit c63e733

File tree

12 files changed

+61
-33
lines changed

12 files changed

+61
-33
lines changed

pyoverkiz/_case.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import functools
66
import re
7-
from collections.abc import Callable
8-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
8+
9+
if TYPE_CHECKING:
10+
from collections.abc import Callable
911

1012
_CAMEL_RE = re.compile(r"([A-Z]+)([A-Z][a-z])|([a-z\d])([A-Z])")
1113

pyoverkiz/action_queue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
import asyncio
66
import contextlib
7-
from collections.abc import Callable, Coroutine, Generator
87
from dataclasses import dataclass
98
from typing import TYPE_CHECKING, Any
109

1110
from pyoverkiz.models import Action
1211

1312
if TYPE_CHECKING:
13+
from collections.abc import Callable, Coroutine, Generator
14+
1415
from pyoverkiz.enums import ExecutionMode
1516

1617

pyoverkiz/auth/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from __future__ import annotations
44

55
import datetime
6-
from collections.abc import Mapping
76
from dataclasses import dataclass
8-
from typing import Any, Protocol
7+
from typing import TYPE_CHECKING, Any, Protocol
8+
9+
if TYPE_CHECKING:
10+
from collections.abc import Mapping
911

1012

1113
@dataclass(slots=True)

pyoverkiz/auth/factory.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from __future__ import annotations
44

5-
import ssl
6-
7-
from aiohttp import ClientSession
5+
from typing import TYPE_CHECKING
86

97
from pyoverkiz.auth.credentials import (
108
Credentials,
@@ -24,7 +22,13 @@
2422
SomfyAuthStrategy,
2523
)
2624
from pyoverkiz.enums import APIType, Server
27-
from pyoverkiz.models import ServerConfig
25+
26+
if TYPE_CHECKING:
27+
import ssl
28+
29+
from aiohttp import ClientSession
30+
31+
from pyoverkiz.models import ServerConfig
2832

2933

3034
def build_auth_strategy(

pyoverkiz/auth/strategies.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
import base64
77
import binascii
88
import json
9-
import ssl
10-
from collections.abc import Mapping
119
from typing import TYPE_CHECKING, Any, cast
1210

1311
if TYPE_CHECKING:
12+
import ssl
13+
from collections.abc import Mapping
14+
1415
from botocore.client import BaseClient
1516

17+
from pyoverkiz.auth.credentials import (
18+
LocalTokenCredentials,
19+
RexelOAuthCodeCredentials,
20+
TokenCredentials,
21+
UsernamePasswordCredentials,
22+
)
23+
from pyoverkiz.models import ServerConfig
24+
1625
from aiohttp import ClientSession, FormData
1726

1827
from pyoverkiz.auth.base import AuthContext, AuthStrategy
19-
from pyoverkiz.auth.credentials import (
20-
LocalTokenCredentials,
21-
RexelOAuthCodeCredentials,
22-
TokenCredentials,
23-
UsernamePasswordCredentials,
24-
)
2528
from pyoverkiz.const import (
2629
COZYTOUCH_ATLANTIC_API,
2730
COZYTOUCH_CLIENT_ID,
@@ -47,7 +50,6 @@
4750
SomfyBadCredentialsError,
4851
SomfyServiceError,
4952
)
50-
from pyoverkiz.models import ServerConfig
5153

5254

5355
class BaseAuthStrategy(AuthStrategy):

pyoverkiz/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import ssl
77
import urllib.parse
88
from pathlib import Path
9-
from types import TracebackType
10-
from typing import Any, cast
9+
from typing import TYPE_CHECKING, Any, cast
1110

1211
import backoff
1312
from aiohttp import (
@@ -16,7 +15,6 @@
1615
ClientSession,
1716
ServerDisconnectedError,
1817
)
19-
from backoff.types import Details
2018

2119
from pyoverkiz._case import decamelize
2220
from pyoverkiz.action_queue import ActionQueue, ActionQueueSettings
@@ -52,7 +50,13 @@
5250
from pyoverkiz.obfuscate import obfuscate_sensitive_data
5351
from pyoverkiz.response_handler import check_response
5452
from pyoverkiz.serializers import prepare_payload
55-
from pyoverkiz.types import JSON
53+
54+
if TYPE_CHECKING:
55+
from types import TracebackType
56+
57+
from backoff.types import Details
58+
59+
from pyoverkiz.types import JSON
5660

5761
_LOGGER = logging.getLogger(__name__)
5862

pyoverkiz/models.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import json
66
import logging
77
import re
8-
from collections.abc import Iterator
9-
from typing import Any, cast
8+
from typing import TYPE_CHECKING, Any, cast
109

1110
from attr import define, field
1211

@@ -24,12 +23,16 @@
2423
UIWidget,
2524
UpdateBoxStatus,
2625
)
27-
from pyoverkiz.enums.command import OverkizCommand, OverkizCommandParam
2826
from pyoverkiz.enums.protocol import Protocol
2927
from pyoverkiz.enums.server import APIType, Server
3028
from pyoverkiz.obfuscate import obfuscate_email, obfuscate_id, obfuscate_string
3129
from pyoverkiz.types import DATA_TYPE_TO_PYTHON, StateType
3230

31+
if TYPE_CHECKING:
32+
from collections.abc import Iterator
33+
34+
from pyoverkiz.enums.command import OverkizCommand, OverkizCommandParam
35+
3336
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals
3437

3538
# <protocol>://<gatewayId>/<deviceAddress>[#<subsystemId>]

pyoverkiz/obfuscate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from __future__ import annotations
44

55
import re
6-
from typing import Any
6+
from typing import TYPE_CHECKING, Any
77

8-
from pyoverkiz.types import JSON
8+
if TYPE_CHECKING:
9+
from pyoverkiz.types import JSON
910

1011

1112
def obfuscate_id(id: str | None) -> str:

pyoverkiz/response_handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from __future__ import annotations
44

55
from json import JSONDecodeError
6-
7-
from aiohttp import ClientResponse
6+
from typing import TYPE_CHECKING
87

98
from pyoverkiz.exceptions import (
109
AccessDeniedToGatewayError,
@@ -36,6 +35,9 @@
3635
UnknownUserError,
3736
)
3837

38+
if TYPE_CHECKING:
39+
from aiohttp import ClientResponse
40+
3941
# Primary dispatch: (errorCode, message_substring) -> error class.
4042
# Checked in order; first match wins. Use errorCode as the primary key to
4143
# reduce brittleness across cloud vs. local API variants.

pyoverkiz/types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from __future__ import annotations
44

55
import json
6-
from collections.abc import Callable
7-
from typing import Any
6+
from typing import TYPE_CHECKING, Any
87

98
from pyoverkiz.enums import DataType
109

10+
if TYPE_CHECKING:
11+
from collections.abc import Callable
12+
1113
StateType = str | int | float | bool | dict[str, Any] | list[Any] | None
1214

1315

0 commit comments

Comments
 (0)