From 9c1348e8e666800788601581889fddedc0687a58 Mon Sep 17 00:00:00 2001 From: awolverp Date: Mon, 25 Nov 2024 12:42:17 +0330 Subject: [PATCH] Use typing_extensions.ParamSpec --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 3 --- cachebox/utils.py | 18 +++++++++++------- pyproject.toml | 4 ++++ 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2fbd66..a5be4d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 4.3.2 - 2024-11-25 +### Added +- New dependency is added: `typing_extensions`. We used this library to use `ParamSpec` that makes `cachebox` type-hint + better, and easier than ever for you. + +### Changed +- the behaviour of the iteratores changed. Previously, iterators used capacity and length of the cache + to know "is cache have changes?". But now, each cache has a number called "state" that increments + with each change; iterators now uses this "state" number. + ## 4.3.1 - 2024-11-18 ### Changed - `__str__` changed to `__repr__` diff --git a/Cargo.lock b/Cargo.lock index ddf373a..2b39e61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cachebox" -version = "4.3.1" +version = "4.3.2" dependencies = [ "cfg-if", "fastrand", diff --git a/Cargo.toml b/Cargo.toml index 9903f08..881e80b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cachebox" -version = "4.3.1" +version = "4.3.2" edition = "2021" description = "The fastest memoizing and caching Python library written in Rust" readme = "README.md" diff --git a/README.md b/README.md index 5f2de2d..b7232ef 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,6 @@ It uses Google's high-performance SwissTable hash map. thanks to [hashbrown](htt **✨ Low memory usage** \ It has very low memory usage. -**⭐ Zero-Dependecy** \ -As we said, `cachebox` written in Rust so you don't have to install any other dependecies. - **🧶 Thread-safe** \ It's completely thread-safe and uses locks to prevent problems. diff --git a/cachebox/utils.py b/cachebox/utils.py index 6898ba1..f9da7e2 100644 --- a/cachebox/utils.py +++ b/cachebox/utils.py @@ -1,4 +1,5 @@ from ._cachebox import BaseCacheImpl, FIFOCache +from typing_extensions import ParamSpec from collections import namedtuple import functools import inspect @@ -187,7 +188,10 @@ def make_typed_key(args: tuple, kwds: dict): EVENT_HIT = 2 -class _cached_wrapper(typing.Generic[VT]): +PS = ParamSpec("PS") + + +class _cached_wrapper(typing.Generic[VT, PS]): def __init__( self, cache: BaseCacheImpl[typing.Any, VT], @@ -233,7 +237,7 @@ def __get__(self, instance, *args): self.instance = instance return self - def __call__(self, *args, **kwds) -> VT: + def __call__(self, *args: PS.args, **kwds: PS.kwargs) -> VT: if self.instance is not _NOT_SETTED: args = (self.instance, *args) @@ -261,8 +265,8 @@ def __call__(self, *args, **kwds) -> VT: return _copy_if_need(result, force=self.always_copy) -class _async_cached_wrapper(_cached_wrapper[VT]): - async def __call__(self, *args, **kwds) -> VT: +class _async_cached_wrapper(_cached_wrapper[VT, PS]): + async def __call__(self, *args: PS.args, **kwds: PS.kwargs) -> VT: if self.instance is not _NOT_SETTED: args = (self.instance, *args) @@ -348,11 +352,11 @@ def sum_as_string(a, b): @typing.overload def decorator( - func: typing.Callable[..., typing.Awaitable[VT]], - ) -> _async_cached_wrapper[VT]: ... + func: typing.Callable[PS, typing.Awaitable[VT]], + ) -> _async_cached_wrapper[VT, PS]: ... @typing.overload - def decorator(func: typing.Callable[..., VT]) -> _cached_wrapper[VT]: ... + def decorator(func: typing.Callable[PS, VT]) -> _cached_wrapper[VT, PS]: ... def decorator(func): if inspect.iscoroutinefunction(func): diff --git a/pyproject.toml b/pyproject.toml index 503566e..0933c01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,10 @@ dynamic = [ 'version' ] +dependencies = [ + 'typing-extensions>=4.6.2', +] + [project.urls] Homepage = 'https://github.com/awolverp/cachebox'