diff --git a/CHANGES/193.feature.rst b/CHANGES/193.feature.rst new file mode 100644 index 00000000..0f88d697 --- /dev/null +++ b/CHANGES/193.feature.rst @@ -0,0 +1,2 @@ +Added support for newer type hints and remove ``Optional`` and ``Union`` from all annotations +-- by :user:`Vizonex` diff --git a/src/propcache/_helpers_py.py b/src/propcache/_helpers_py.py index 1374fc6d..db5b8d63 100644 --- a/src/propcache/_helpers_py.py +++ b/src/propcache/_helpers_py.py @@ -1,9 +1,11 @@ """Various helper functions.""" +from __future__ import annotations + import sys -from collections.abc import Mapping +from collections.abc import Callable, Mapping from functools import cached_property -from typing import Any, Callable, Generic, Optional, Protocol, TypeVar, Union, overload +from typing import Any, Generic, Protocol, TypeVar, overload __all__ = ("under_cached_property", "cached_property") @@ -39,16 +41,16 @@ def __init__(self, wrapped: Callable[[Any], _T]) -> None: self.name = wrapped.__name__ @overload - def __get__(self, inst: None, owner: Optional[type[object]] = None) -> Self: ... + def __get__(self, inst: None, owner: type[object] | None = None) -> Self: ... @overload def __get__( - self, inst: _CacheImpl[Any], owner: Optional[type[object]] = None + self, inst: _CacheImpl[Any], owner: type[object] | None = None ) -> _T: ... def __get__( - self, inst: Optional[_CacheImpl[Any]], owner: Optional[type[object]] = None - ) -> Union[_T, Self]: + self, inst: _CacheImpl[Any] | None, owner: type[object] | None = None + ) -> _T | Self: if inst is None: return self try: