Skip to content

Commit 96c4e05

Browse files
committed
chore: enforce typing import ban with lint rule
We now use ruff/flake8-tidy-imports to ban importing typing/typing_extensions. Unfortunately it doesn't seem to support banning everything except allow-listed items, so we have to ignore places that need to import Literal and overload from typing (due to ruff mis-handling them when they're imported from our typing module).
1 parent 45f1517 commit 96c4e05

22 files changed

+35
-24
lines changed

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ select = [
8787
"FA", # flake8-future-annotations
8888
"PYI", # flake8-pyi
8989
"I",
90+
"TID", # flake8-tidy-imports
9091
]
9192

9293
ignore = [
@@ -102,6 +103,10 @@ ignore = [
102103
"PYI041",
103104
]
104105

106+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
107+
"typing_extensions".msg = "use denokv._pycompat.typing instead, typing_extensions is not a runtime dependency."
108+
"typing".msg = "Use denokv._pycompat.typing instead (apart from overload and Literal), using typing is error-prone as it has many differences between python versions."
109+
105110
[tool.ruff.lint.pydocstyle]
106111
convention = "numpy"
107112

src/denokv/_kv_writes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from functools import total_ordering
1010
from itertools import islice
1111
from types import MappingProxyType
12-
from typing import Literal
13-
from typing import overload
12+
from typing import Literal # noqa: TID251
13+
from typing import overload # noqa: TID251
1414

1515
from v8serialize import Encoder
1616
from v8serialize.constants import FLOAT64_SAFE_INT_RANGE

src/denokv/_pycompat/dataclasses.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from dataclasses import FrozenInstanceError
55
from dataclasses import dataclass
66
from dataclasses import fields as dataclass_fields
7-
from typing import Literal
8-
from typing import TypedDict # avoid circular reference with _pycompat.typing
7+
from typing import Literal # noqa: TID251
8+
9+
# avoid circular reference with _pycompat.typing
10+
from typing import TypedDict # noqa: TID251
911

1012

1113
class NoArg(TypedDict):

src/denokv/_pycompat/protobuf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import overload
3+
from typing import overload # noqa: TID251
44

55
from denokv._datapath_pb2 import AtomicWriteStatus
66
from denokv._datapath_pb2 import MutationType

src/denokv/_pycompat/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Literal
2+
from typing import Literal # noqa: TID251
33

44
from denokv._pycompat.typing import TypeAlias
55

src/denokv/_pycompat/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
without needing if TYPE_CHECKING everywhere.
77
"""
88

9+
# ruff: noqa: TID251
10+
911
from __future__ import annotations
1012

1113
from dataclasses import dataclass

src/denokv/backoff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass
77
from enum import IntEnum
88
from itertools import count
9-
from typing import Literal
9+
from typing import Literal # noqa: TID251
1010

1111
from denokv._pycompat.typing import Callable
1212
from denokv._pycompat.typing import Iterable

src/denokv/datapath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dataclasses import dataclass
1010
from enum import Enum
1111
from enum import auto
12-
from typing import overload
12+
from typing import overload # noqa: TID251
1313

1414
import aiohttp
1515
import aiohttp.client_exceptions

src/denokv/kv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from functools import partial
1313
from os import environ
1414
from types import TracebackType
15-
from typing import Literal
16-
from typing import overload
15+
from typing import Literal # noqa: TID251
16+
from typing import overload # noqa: TID251
1717

1818
import aiohttp
1919
import v8serialize

src/denokv/kv_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from dataclasses import dataclass
66
from dataclasses import field
7-
from typing import overload
7+
from typing import overload # noqa: TID251
88

99
from fdb.tuple import pack
1010
from fdb.tuple import unpack

0 commit comments

Comments
 (0)