Skip to content

cachetools: Fix invalid TypeVar usage #8073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions stubs/cachetools/cachetools/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ _VT = TypeVar("_VT")
_T = TypeVar("_T")

class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ...
@overload
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(self, maxsize: float, getsizeof: None = ...) -> None: ...
def __getitem__(self, key: _KT) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT) -> None: ...
def __delitem__(self, key: _KT) -> None: ...
Expand All @@ -30,29 +33,32 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@staticmethod
def getsizeof(value: _VT) -> float: ...

class FIFOCache(Cache[_KT, _VT]):
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ...

class LFUCache(Cache[_KT, _VT]):
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ...

class LRUCache(Cache[_KT, _VT]):
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ...

class MRUCache(Cache[_KT, _VT]):
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ...
class FIFOCache(Cache[_KT, _VT]): ...
class LFUCache(Cache[_KT, _VT]): ...
class LRUCache(Cache[_KT, _VT]): ...
class MRUCache(Cache[_KT, _VT]): ...

class RRCache(Cache[_KT, _VT]):
def __init__(
self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] | None = ..., getsizeof: Callable[[_VT], float] | None = ...
) -> None: ...
@overload
def __init__(self, maxsize: float, choice: None = ..., getsizeof: None = ...) -> None: ...
@overload
def __init__(self, maxsize: float, *, getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(self, maxsize: float, choice: None, getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: None = ...) -> None: ...
@overload
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ...
@property
def choice(self) -> Callable[[Sequence[_KT]], _KT]: ...

class _TimedCache(Cache[_KT, _VT]):
def __init__(
self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ...
) -> None: ...
@overload
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: None = ...) -> None: ...
@overload
def __init__(self, maxsize: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]) -> None: ...
@property
def currsize(self) -> float: ...

Expand All @@ -66,8 +72,13 @@ class _TimedCache(Cache[_KT, _VT]):
def timer(self) -> _Timer: ...

class TTLCache(_TimedCache[_KT, _VT]):
@overload
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: None = ...) -> None: ...
@overload
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
@overload
def __init__(
self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ...
self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this overload redundant with overload 2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not, it'd need typing.NO_DEFAULT.

) -> None: ...
@property
def ttl(self) -> float: ...
Expand Down