Skip to content

Commit cbf98d6

Browse files
committed
fix: ruff errors
1 parent 7e828ea commit cbf98d6

File tree

14 files changed

+37
-29
lines changed

14 files changed

+37
-29
lines changed

src/typed_diskcache/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
def __getattr__(name: str) -> object:
3333
if name == "__version__": # pragma: no cover
34-
from importlib.metadata import version
34+
from importlib.metadata import version # noqa: PLC0415
3535

3636
_version = globals()["__version__"] = version("typed-diskcache")
3737
return _version

src/typed_diskcache/core/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import annotations # noqa: A005
1+
from __future__ import annotations
22

33
import sys
44
from datetime import datetime, timedelta, timezone

src/typed_diskcache/database/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __getstate__(self) -> Mapping[str, Any]:
6464
}
6565

6666
def __setstate__(self, state: Mapping[str, Any]) -> None:
67-
from typed_diskcache.model import Settings
67+
from typed_diskcache.model import Settings # noqa: PLC0415
6868

6969
self._database = Path(state["database"])
7070
self.timeout = state["timeout"]
@@ -164,7 +164,7 @@ async def asession(
164164
) -> AsyncGenerator[AsyncSession, None]:
165165
"""Connect to the database."""
166166
validate_installed("anyio", "Consider installing extra `asyncio`.")
167-
import anyio.lowlevel
167+
import anyio.lowlevel # noqa: PLC0415
168168

169169
session = self._acontext.get()
170170
if session is not None:

src/typed_diskcache/database/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from datetime import datetime, timedelta, timezone
4-
from typing import TYPE_CHECKING, Any, ClassVar, Generic, Optional
4+
from typing import TYPE_CHECKING, Any, ClassVar, Generic
55

66
import cloudpickle
77
import sqlalchemy as sa
@@ -198,12 +198,12 @@ class Cache(Base):
198198
raw: Mapped[bool]
199199
store_time: Mapped[float]
200200
access_time: Mapped[float]
201-
_filepath: Mapped[Optional[str]] = mapped_column( # noqa: UP007
201+
_filepath: Mapped[str | None] = mapped_column(
202202
"filepath", sa.String(), nullable=True
203203
)
204-
value: Mapped[Optional[bytes]] = mapped_column(repr=False) # noqa: UP007
204+
value: Mapped[bytes | None] = mapped_column(repr=False)
205205

206-
expire_time: Mapped[Optional[float]] = mapped_column( # noqa: UP007
206+
expire_time: Mapped[float | None] = mapped_column(
207207
default=None, server_default=sa.literal(None, type_=sa.Float())
208208
)
209209
mode: Mapped[CacheMode] = mapped_column(

src/typed_diskcache/database/revision/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _downgrade_process(
204204

205205

206206
def _parse_revision(conn: Connection) -> Revision | None:
207-
from typed_diskcache.database.model import Version
207+
from typed_diskcache.database.model import Version # noqa: PLC0415
208208

209209
try:
210210
version = Version.get(conn)

src/typed_diskcache/implement/cache/default/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class or callable. Default is `None`.
8181

8282
__slots__ = ("_conn", "_directory", "_disk", "_page_size", "_settings")
8383

84+
@override
85+
def __hash__(self) -> int:
86+
return hash(self.directory)
87+
8488
def __init__(
8589
self,
8690
directory: str | PathLike[str] | None = None,
@@ -170,7 +174,7 @@ def __aiter__(self) -> AsyncIterator[Any]:
170174

171175
@override
172176
def __getstate__(self) -> Mapping[str, Any]:
173-
import cloudpickle
177+
import cloudpickle # noqa: PLC0415
174178

175179
return {
176180
"directory": str(self.directory),
@@ -182,9 +186,9 @@ def __getstate__(self) -> Mapping[str, Any]:
182186

183187
@override
184188
def __setstate__(self, state: Mapping[str, Any]) -> None:
185-
import cloudpickle
189+
import cloudpickle # noqa: PLC0415
186190

187-
from typed_diskcache.model import Settings
191+
from typed_diskcache.model import Settings # noqa: PLC0415
188192

189193
self._directory = Path(state["directory"])
190194
self._disk = cloudpickle.loads(state["disk"])

src/typed_diskcache/implement/cache/default/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def extend_queue(
274274
stream: MemoryObjectSendStream[_T],
275275
) -> Callable[[Iterable[_T]], Awaitable[Any]]:
276276
validate_installed("anyio", "Consider installing extra `asyncio`.")
277-
import anyio
277+
import anyio # noqa: PLC0415
278278

279279
async def extend(items: Iterable[_T]) -> None:
280280
logger.debug("Stream stats: %r", stream.statistics())
@@ -461,7 +461,7 @@ async def async_transact(
461461
stacklevel: int = 3,
462462
) -> AsyncGenerator[tuple[AsyncSession, AsyncCleanupFunc], None]:
463463
validate_installed("anyio", "Consider installing extra `asyncio`.")
464-
import anyio
464+
import anyio # noqa: PLC0415
465465

466466
send, receive = anyio.create_memory_object_stream["str | PathLike[str] | None"](
467467
1_000_000
@@ -1060,7 +1060,7 @@ async def acheck_file_exists( # noqa: PLR0913
10601060
stacklevel: int = 3,
10611061
) -> None:
10621062
validate_installed("anyio", "Consider installing extra `asyncio`.")
1063-
import anyio
1063+
import anyio # noqa: PLC0415
10641064

10651065
full_path: anyio.Path = anyio.Path(directory) / row.filepath
10661066
filenames.add(full_path)
@@ -1097,7 +1097,7 @@ async def acheck_unknown_file(
10971097
stacklevel: int = 3,
10981098
) -> None:
10991099
validate_installed("anyio", "Consider installing extra `asyncio`.")
1100-
import anyio
1100+
import anyio # noqa: PLC0415
11011101

11021102
paths = {anyio.Path(dirpath) / file for file in files}
11031103
error = paths - filenames
@@ -1124,7 +1124,7 @@ async def acheck_empty_dir(
11241124
stacklevel: int = 3,
11251125
) -> None:
11261126
validate_installed("anyio", "Consider installing extra `asyncio`.")
1127-
import anyio
1127+
import anyio # noqa: PLC0415
11281128

11291129
if not (dirs or files):
11301130
message = f"Empty directory: {dirpath}"

src/typed_diskcache/implement/cache/fanout/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __aiter__(self) -> AsyncIterator[Any]:
150150

151151
@override
152152
def __getstate__(self) -> Mapping[str, Any]:
153-
import cloudpickle
153+
import cloudpickle # noqa: PLC0415
154154

155155
return {
156156
"shards": cloudpickle.dumps(self._shards),
@@ -159,7 +159,7 @@ def __getstate__(self) -> Mapping[str, Any]:
159159

160160
@override
161161
def __setstate__(self, state: Mapping[str, Any]) -> None:
162-
import cloudpickle
162+
import cloudpickle # noqa: PLC0415
163163

164164
cache: Shard = cloudpickle.loads(state["cache"])
165165
shards: tuple[Shard] = cloudpickle.loads(state["shards"])
@@ -322,7 +322,7 @@ def stats(self, *, enable: bool = True, reset: bool = False) -> Stats:
322322
@override
323323
async def astats(self, *, enable: bool = True, reset: bool = False) -> Stats:
324324
validate_installed("anyio", "Consider installing extra `asyncio`.")
325-
import anyio
325+
import anyio # noqa: PLC0415
326326

327327
hits, misses = 0, 0
328328

@@ -348,7 +348,7 @@ def close(self) -> None:
348348
@override
349349
async def aclose(self) -> None:
350350
validate_installed("anyio", "Consider installing extra `asyncio`.")
351-
import anyio
351+
import anyio # noqa: PLC0415
352352

353353
await self.conn.aclose()
354354
async with anyio.create_task_group() as task_group:
@@ -704,7 +704,7 @@ async def aupdate_settings(
704704
**kwargs: Unpack[SettingsKwargs],
705705
) -> None:
706706
validate_installed("anyio", "Consider installing extra `asyncio`.")
707-
import anyio
707+
import anyio # noqa: PLC0415
708708

709709
settings = cache_utils.combine_settings(settings, kwargs)
710710
async with anyio.create_task_group() as task_group:

src/typed_diskcache/implement/disk/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ async def afetch( # noqa: PLR0911
276276
self, *, mode: CacheMode, filename: str | PathLike[str] | None, value: Any
277277
) -> Any:
278278
validate_installed("anyio", "Consider installing extra `asyncio`.")
279-
import anyio
279+
import anyio # noqa: PLC0415
280280

281281
if mode == CacheMode.NONE:
282282
logger.debug("Fetching null value")
@@ -333,7 +333,7 @@ def remove(self, file_path: str | PathLike[str]) -> None:
333333
@override
334334
async def aremove(self, file_path: str | PathLike[str]) -> None:
335335
validate_installed("anyio", "Consider installing extra `asyncio`.")
336-
import anyio
336+
import anyio # noqa: PLC0415
337337

338338
full_path = anyio.Path(self.directory / file_path)
339339
full_dir = full_path.parent

src/typed_diskcache/implement/disk/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def async_write(
9191
encoding: str | None = None,
9292
) -> int | None:
9393
validate_installed("anyio", "Consider installing extra `asyncio`.")
94-
import anyio
94+
import anyio # noqa: PLC0415
9595

9696
full_path = anyio.Path(full_path)
9797
full_dir = full_path.parent

0 commit comments

Comments
 (0)