@@ -379,6 +379,8 @@ class Threaded(ThreadedBase[P, T]):
379379 func_type : type
380380
381381 def __init__ (self , func : Callable [P , T ]) -> None :
382+ self .__wrapped : Dict [Any , Any ] = {}
383+
382384 if isinstance (func , staticmethod ):
383385 self .func_type = staticmethod
384386 self .func = func .__func__
@@ -415,14 +417,22 @@ def __get__(
415417 instance : Any ,
416418 owner : Optional [type ] = None ,
417419 ) -> "Threaded[P, T] | BoundThreaded[Any, T]" :
420+ key = (instance , owner )
421+ if key in self .__wrapped :
422+ return self .__wrapped [key ]
423+
418424 if self .func_type is staticmethod :
419- return self
425+ result = self
420426 elif self .func_type is classmethod :
421427 cls = owner if instance is None else type (instance )
422- return BoundThreaded (self .func , cls )
428+ result = BoundThreaded (self .func , cls )
423429 elif instance is not None :
424- return BoundThreaded (self .func , instance )
425- return self
430+ result = BoundThreaded (self .func , instance )
431+ else :
432+ result = self
433+
434+ self .__wrapped [key ] = result
435+ return result
426436
427437
428438class BoundThreaded (ThreadedBase [P , T ]):
@@ -570,6 +580,7 @@ def __init__(
570580
571581 self .func = actual_func
572582 self .max_size = max_size
583+ self .__wrapped : Dict [Any , Any ] = {}
573584
574585 @overload
575586 def __get__ (
@@ -592,14 +603,22 @@ def __get__(
592603 instance : Any ,
593604 owner : Optional [type ] = None ,
594605 ) -> "ThreadedIterable[P, T] | BoundThreadedIterable[Any, T]" :
606+ key = (instance , owner )
607+ if key in self .__wrapped :
608+ return self .__wrapped [key ]
609+
595610 if self .func_type is staticmethod :
596- return self
611+ result = self
597612 elif self .func_type is classmethod :
598613 cls = owner if instance is None else type (instance )
599- return BoundThreadedIterable (self .func , cls , self .max_size )
614+ result = BoundThreadedIterable (self .func , cls , self .max_size )
600615 elif instance is not None :
601- return BoundThreadedIterable (self .func , instance , self .max_size )
602- return self
616+ result = BoundThreadedIterable (self .func , instance , self .max_size )
617+ else :
618+ result = self
619+
620+ self .__wrapped [key ] = result
621+ return result
603622
604623
605624class BoundThreadedIterable (ThreadedIterableBase [P , T ]):
0 commit comments