Skip to content

Commit 9c1348e

Browse files
committed
Use typing_extensions.ParamSpec
1 parent 09b6eb5 commit 9c1348e

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 4.3.2 - 2024-11-25
9+
### Added
10+
- New dependency is added: `typing_extensions`. We used this library to use `ParamSpec` that makes `cachebox` type-hint
11+
better, and easier than ever for you.
12+
13+
### Changed
14+
- the behaviour of the iteratores changed. Previously, iterators used capacity and length of the cache
15+
to know "is cache have changes?". But now, each cache has a number called "state" that increments
16+
with each change; iterators now uses this "state" number.
17+
818
## 4.3.1 - 2024-11-18
919
### Changed
1020
- `__str__` changed to `__repr__`

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cachebox"
3-
version = "4.3.1"
3+
version = "4.3.2"
44
edition = "2021"
55
description = "The fastest memoizing and caching Python library written in Rust"
66
readme = "README.md"

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ It uses Google's high-performance SwissTable hash map. thanks to [hashbrown](htt
6363
**✨ Low memory usage** \
6464
It has very low memory usage.
6565

66-
**⭐ Zero-Dependecy** \
67-
As we said, `cachebox` written in Rust so you don't have to install any other dependecies.
68-
6966
**🧶 Thread-safe** \
7067
It's completely thread-safe and uses locks to prevent problems.
7168

cachebox/utils.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ._cachebox import BaseCacheImpl, FIFOCache
2+
from typing_extensions import ParamSpec
23
from collections import namedtuple
34
import functools
45
import inspect
@@ -187,7 +188,10 @@ def make_typed_key(args: tuple, kwds: dict):
187188
EVENT_HIT = 2
188189

189190

190-
class _cached_wrapper(typing.Generic[VT]):
191+
PS = ParamSpec("PS")
192+
193+
194+
class _cached_wrapper(typing.Generic[VT, PS]):
191195
def __init__(
192196
self,
193197
cache: BaseCacheImpl[typing.Any, VT],
@@ -233,7 +237,7 @@ def __get__(self, instance, *args):
233237
self.instance = instance
234238
return self
235239

236-
def __call__(self, *args, **kwds) -> VT:
240+
def __call__(self, *args: PS.args, **kwds: PS.kwargs) -> VT:
237241
if self.instance is not _NOT_SETTED:
238242
args = (self.instance, *args)
239243

@@ -261,8 +265,8 @@ def __call__(self, *args, **kwds) -> VT:
261265
return _copy_if_need(result, force=self.always_copy)
262266

263267

264-
class _async_cached_wrapper(_cached_wrapper[VT]):
265-
async def __call__(self, *args, **kwds) -> VT:
268+
class _async_cached_wrapper(_cached_wrapper[VT, PS]):
269+
async def __call__(self, *args: PS.args, **kwds: PS.kwargs) -> VT:
266270
if self.instance is not _NOT_SETTED:
267271
args = (self.instance, *args)
268272

@@ -348,11 +352,11 @@ def sum_as_string(a, b):
348352

349353
@typing.overload
350354
def decorator(
351-
func: typing.Callable[..., typing.Awaitable[VT]],
352-
) -> _async_cached_wrapper[VT]: ...
355+
func: typing.Callable[PS, typing.Awaitable[VT]],
356+
) -> _async_cached_wrapper[VT, PS]: ...
353357

354358
@typing.overload
355-
def decorator(func: typing.Callable[..., VT]) -> _cached_wrapper[VT]: ...
359+
def decorator(func: typing.Callable[PS, VT]) -> _cached_wrapper[VT, PS]: ...
356360

357361
def decorator(func):
358362
if inspect.iscoroutinefunction(func):

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ dynamic = [
3838
'version'
3939
]
4040

41+
dependencies = [
42+
'typing-extensions>=4.6.2',
43+
]
44+
4145
[project.urls]
4246
Homepage = 'https://github.com/awolverp/cachebox'
4347

0 commit comments

Comments
 (0)