@@ -58,10 +58,9 @@ class _HashCallable(Protocol):
58
58
def __call__ (self , / , * args : Hashable , ** kwargs : Hashable ) -> Never : ...
59
59
60
60
@type_check_only
61
- class _LruCacheWrapperBase (Protocol [_out_TCallable ]):
62
- __wrapped__ : Final [_out_TCallable ] = ... # type: ignore[misc]
63
- __call__ : Final [_out_TCallable | _HashCallable ] = ... # type: ignore[misc]
64
-
61
+ class _LruCacheWrapperBase (Generic [_out_TCallable ]):
62
+ __wrapped__ : Final [_out_TCallable ] # type: ignore[misc]
63
+ __call__ : Final [_out_TCallable | _HashCallable ] # type: ignore[misc]
65
64
66
65
def cache_info (self ) -> _CacheInfo : ...
67
66
def cache_clear (self ) -> None : ...
@@ -71,23 +70,28 @@ class _LruCacheWrapperBase(Protocol[_out_TCallable]):
71
70
def __copy__ (self ) -> Self : ...
72
71
def __deepcopy__ (self , memo : Any , / ) -> Self : ...
73
72
74
- @final
73
+
74
+ # replace with `Method & X` once #856 is resolved
75
+ @type_check_only
76
+ class _LruCacheWrapperMethod (MethodType , _LruCacheWrapperBase [_out_TCallable ]): # type: ignore[misc]
77
+ __call__ : Final [_out_TCallable | _HashCallable ] # type: ignore[misc, assignment]
78
+
79
+
75
80
# actually defined in `_functools`
81
+ @final
76
82
class _lru_cache_wrapper (_LruCacheWrapperBase [_out_TCallable ]):
77
83
def __init__ (self , user_function : Never , maxsize : Never , typed : Never , cache_info_type : Never ): ...
78
84
79
- # TODO: reintroduce this once mypy 1.14 fork is merged
80
- # @overload
81
- # def __get__(self, instance: None, owner: object) -> Self: ...
82
- # @overload
85
+ @overload
86
+ def __get__ (self , instance : None , owner : object ) -> Self : ...
87
+ @overload
83
88
def __get__ (
84
89
self : _lru_cache_wrapper [Callable [Concatenate [Never , _PWrapped ], _RWrapped ]],
85
90
instance : object ,
86
91
owner : type [object ] | None = None ,
87
92
/ ,
88
- # ideally, we would capture the Callable here, and intersect with `MethodType`
89
- ) -> _LruCacheWrapperBase [Callable [_PWrapped , _RWrapped ]]: ...
90
-
93
+ # ideally we could capture the `Callable` to account for subtypes and intersect with `MethodType`
94
+ ) -> _LruCacheWrapperMethod [Callable [_PWrapped , _RWrapped ]]: ...
91
95
92
96
@overload
93
97
def lru_cache (maxsize : int | None = 128 , typed : bool = False ) -> FunctionType [[_TCallable ], _lru_cache_wrapper [_TCallable ]]: ...
0 commit comments