Skip to content

Commit 925f7ec

Browse files
committed
Enable TCH rules for slightly reducing runtime imports.
Catches typing imports that are only needed for type checking.
1 parent cc7e525 commit 925f7ec

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ exclude = [
8585

8686
[tool.ruff]
8787
line-length = 79
88-
select = ["ANN", "B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "UP", "W"]
88+
select = [
89+
"ANN", "B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "TCH", "UP", "W",
90+
]
8991
ignore = [
9092
# Wat, type annotations for self and cls, why is this a thing?
9193
"ANN101",

referencing/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import attrs
99

1010
from referencing._attrs import frozen
11-
from referencing.typing import URI
1211

1312
if TYPE_CHECKING:
1413
from referencing import Resource
14+
from referencing.typing import URI
1515

1616

1717
@frozen

referencing/retrieval.py

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

66
from functools import lru_cache
7-
from typing import Callable, TypeVar
7+
from typing import TYPE_CHECKING, Callable, TypeVar
88
import json
99

1010
from referencing import Resource
11-
from referencing.typing import URI, D, Retrieve
11+
12+
if TYPE_CHECKING:
13+
from referencing.typing import URI, D, Retrieve
1214

1315
#: A serialized document (e.g. a JSON string)
1416
_T = TypeVar("_T")

0 commit comments

Comments
 (0)