
    wBf                     N    d dl mZ d dlmZ d dlmZ d Zd Zd Z G d d      Z	y	)
    )Hashable)GeneratorTypewrapsc                 .     t                fd       }|S )a  
    Decorator to cause a method to cache it's results in self for each
    combination of inputs and return the cached result on subsequent calls.
    Does not support named arguments or arg values that are not hashable.

    >>> class Foo (object):
    ...   @memoizemethod
    ...   def foo(self, x, y=0):
    ...     print('running method with', x, y)
    ...     return x + y + 3
    ...
    >>> foo1 = Foo()
    >>> foo2 = Foo()
    >>> foo1.foo(10)
    running method with 10 0
    13
    >>> foo1.foo(10)
    13
    >>> foo2.foo(11, y=7)
    running method with 11 7
    21
    >>> foo2.foo(11)
    running method with 11 0
    14
    >>> foo2.foo(11, y=7)
    21
    >>> class Foo (object):
    ...   def __init__(self, lower):
    ...     self.lower = lower
    ...   @memoizemethod
    ...   def range_tuple(self, upper):
    ...     print('running function')
    ...     return tuple(i for i in range(self.lower, upper))
    ...   @memoizemethod
    ...   def range_iter(self, upper):
    ...     print('running function')
    ...     return (i for i in range(self.lower, upper))
    ...
    >>> foo = Foo(3)
    >>> foo.range_tuple(6)
    running function
    (3, 4, 5)
    >>> foo.range_tuple(7)
    running function
    (3, 4, 5, 6)
    >>> foo.range_tuple(6)
    (3, 4, 5)
    >>> foo.range_iter(6)
    Traceback (most recent call last):
    TypeError: Can't memoize a generator or non-hashable object!
    c                    d| j                   vri | _        | j                  }j                  |t        t	        |j                                     f}||v r||   S 	  | g|i |}t        |t              st        |t              st        d      |j                  ||      S # t        $ r}dt        |      v rd }n Y d }~\d }~ww xY w)N_memoized_results__wrapped__z1Can't memoize a generator or non-hashable object!)__dict__r	   __name__tuplesorteditemsKeyErrorstr
isinstancer   r   	TypeError
setdefault)selfargskwargsmemoized_resultskeyresultemethods          7lib/python3.12/site-packages/conda/auxlib/decorators.py_wrapperzmemoizemethod.<locals>._wrapper?   s     dmm3%'D"11eF6<<>,B&CD""#C((6t6v6 &-0
688T STT#..sF;;   CF*!F s   B% %	C	.CC	r   )r   r   s   ` r   memoizemethodr   
   s#    j 6]< <8 O    c                     t        t        | di       j                               D ]  }|d   |v s| j                  |=  | j                  }|D ]  }d|z  }||v s||=  y)a  
    Clear the memoized method or @memoizedproperty results for the given
    method names from the given object.

    >>> v = [0]
    >>> def inc():
    ...     v[0] += 1
    ...     return v[0]
    ...
    >>> class Foo(object):
    ...    @memoizemethod
    ...    def foo(self):
    ...        return inc()
    ...    @memoizedproperty
    ...    def g(self):
    ...       return inc()
    ...
    >>> f = Foo()
    >>> f.foo(), f.foo()
    (1, 1)
    >>> clear_memoized_methods(f, 'foo')
    >>> (f.foo(), f.foo(), f.g, f.g)
    (2, 2, 3, 3)
    >>> (f.foo(), f.foo(), f.g, f.g)
    (2, 2, 3, 3)
    >>> clear_memoized_methods(f, 'g', 'no_problem_if_undefined')
    >>> f.g, f.foo(), f.g
    (4, 2, 4)
    >>> f.foo()
    2
    r	   r   __%sN)listgetattrkeysr	   _cache_)objmethod_namesr   property_dictpropinner_attnames         r   clear_memoized_methodsr,   _   sy    @ GC!4b9>>@A +q6\!%%c*+
 KKM -M)m,-r    c                 F     d j                   z   fd}t        |      S )a  
    Decorator to cause a method to cache it's results in self for each
    combination of inputs and return the cached result on subsequent calls.
    Does not support named arguments or arg values that are not hashable.

    >>> class Foo (object):
    ...   _x = 1
    ...   @memoizedproperty
    ...   def foo(self):
    ...     self._x += 1
    ...     print('updating and returning {0}'.format(self._x))
    ...     return self._x
    ...
    >>> foo1 = Foo()
    >>> foo2 = Foo()
    >>> foo1.foo
    updating and returning 2
    2
    >>> foo1.foo
    2
    >>> foo2.foo
    updating and returning 2
    2
    >>> foo1.foo
    2
    r"   c                 j    t        | d      si | _        | j                  }|vr |       |<   |   S )Nr&   )hasattrr&   )r   cachefuncr+   s     r   new_fgetz"memoizedproperty.<locals>.new_fget   s>    tY'DL%#':E- ]##r    )r   property)r1   r2   r+   s   ` @r   memoizedpropertyr4      s%    6 T]]*M$ Hr    c                   (    e Zd ZddZddZd Zd Zy)classpropertyNc                 $   |t        |t              st        |      }|t        |t              st        |      }|| _        || _        |j	                  t
              }|j                  | _        |j                  | _        |j                  | _        y N)	r   classmethod_classproperty__get_classproperty__set__get__object__doc__r   
__module__)r   gettersetterinfos       r   __init__zclassproperty.__init__   sq    j&E (Fj&E (F

~~f%||//r    c                 d    |r||j                   } | j                  j                  ||             S r8   )	__class__r:   r<   )r   r'   type_s      r   r<   zclassproperty.__get__   s.    5=MME-tzz!!#u-//r    c                 L    || S  | j                   j                  |      |      S r8   )r;   r<   )r   r'   values      r   __set__zclassproperty.__set__   s(    ;K&tzz!!#&u--r    c                 :    | j                  | j                  |      S r8   )rE   r:   )r   rA   s     r   rA   zclassproperty.setter   s    ~~djj&11r    )NNr8   )r   r?   __qualname__rC   r<   rI   rA    r    r   r6   r6      s    *0
.
2r    r6   N)
collections.abcr   typesr   	functoolsr   r   r,   r4   r6   rL   r    r   <module>rP      s+    $  Rj)-X%P2 2r    