
    .dg                    P   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ ddlmZmZmZmZ ddlmZmZ er( e	d	e

      Zeez  Z G d de      Z G d dee         Zeddd	 	 	 	 	 	 	 dd       Zeddd	 	 	 	 	 	 	 	 	 dd       Zeddd	 	 	 	 	 	 	 	 	 	 	 dd       Zy)    )annotationsN)defaultdict)wraps)TYPE_CHECKINGTypeVarCallableProtocol	TypedDictoverload   )	ParameterParameterizedParameterizedMetaclasstransform_reference)accept_argumentsiscoroutinefunction	CallableT)boundc                  6    e Zd ZU ded<   ded<   ded<   ded<   y)	DependencyInfoztuple[Dependency, ...]dependencieszdict[str, Dependency]kwboolwatchon_initN__name__
__module____qualname____annotations__     -lib/python3.12/site-packages/param/depends.pyr   r      s    ,,!!r"   r   c                  "    e Zd ZU ded<   ded<   y)DependsFuncr   _dinfor   __call__Nr   r!   r"   r#   r%   r%      s    r"   r%   .)r   r   c                     y Nr!   )r   r   r   s      r#   dependsr*           r"   c                     y r)   r!   )r   r   r   r   s       r#   r*   r*   "   r+   r"   Fc         	     4    t        d D              j                         D ci c]  \  }}|t        |       c}}ct        j                         rt                fd       }n[t        j                         rt                fd       }n2t               rt                fd       }nt                fd       }t              t        j                               z   }d}	|D ]  }
t        |
t              rd}	t        |
d      r#t        |
t              s!t        d	t        |
      j                   z        t        |
j"                  t$              rot        |
j"                  t&              r|
j"                  d
n!dt        |
j"                        j                   z  }t        d|z         t)        d |D              rt)        d |D              rt        d      |	rrt+        d      |	s|rt        j                         r fd}n7t        j                         r fd}nt               r fd}n fd}t-        t              }|D ])  }
|t/        |
j"                           j1                  |
       + |j                         D ]C  }|d   j"                  j2                  j5                  ||D 
cg c]  }
|
j6                   c}
       E t9         di       }|j;                  ||d       ||_        |S c c}}w c c}
w )a  
    Annotates a function or Parameterized method to express its dependencies.

    The specified dependencies can be either be Parameter instances or if a
    method is supplied they can be defined as strings referring to Parameters
    of the class, or Parameters of subobjects (Parameterized objects that are
    values of this object's parameters). Dependencies can either be on
    Parameter values, or on other metadata about the Parameter.

    Parameters
    ----------
    watch : bool, optional
        Whether to invoke the function/method when the dependency is updated,
        by default False
    on_init : bool, optional
        Whether to invoke the function/method when the instance is created,
        by default False

    c              3  2   K   | ]  }t        |        y wr)   )r   ).0args     r#   	<genexpr>zdepends.<locals>.<genexpr>@   s     ?,3!#&,s   c               ?  0   K    | i |D ]  }|  y wr)   r!   argsr   valfuncs      r#   _dependszdepends.<locals>._dependsE   s      T(R(	 )s   c                B   K    | i |2 3 d {   }| 7 
6 y wr)   r!   r3   s      r#   r7   zdepends.<locals>._dependsJ   s)     !4.2. c	.s   	c                 0   K    | i | d {   S 7 wr)   r!   r4   r   r6   s     r#   r7   zdepends.<locals>._dependsO   s     t*r****s   c                      | i |S r)   r!   r:   s     r#   r7   zdepends.<locals>._dependsS   s    $$$r"   FTr&   zvThe depends decorator only accepts string types referencing a parameter or parameter instances, found %s type instead.Nonez%s classziParameters supplied to the depends decorator, must be bound to a Parameterized class or instance, not %s.c              3  <   K   | ]  }t        |t                y wr)   )
isinstancer   r/   deps     r#   r1   zdepends.<locals>.<genexpr>j   s     7$3JsI&$   c              3  <   K   | ]  }t        |t                y wr)   )r>   strr?   s     r#   r1   zdepends.<locals>.<genexpr>k   s     1DSJsC DrA   zDependencies must either be defined as strings referencing parameters on the class defining the decorated method or as parameter instances. Mixing of string specs and parameter instances is not supported.zlSupplying keywords to the decorated method or function is not supported when referencing parameters by name.c            	   7     K   d D        }j                         D ci c]&  \  }}|t        |j                  |j                        ( }}} |i |D ]  }|  y c c}}w w)Nc              3  \   K   | ]$  }t        |j                  |j                         & y wr)   getattrownernamer?   s     r#   r1   z&depends.<locals>.cb.<locals>.<genexpr>y         M		3884   *,itemsrG   rH   rI   	eventsr4   nr@   
dep_kwargsr5   r   r6   r   s	         r#   cbzdepends.<locals>.cbx   sb     MMLNHHJWJ&!SaCHH!==J
W44CI 5 Xs   A&+A A&c            	       K   d D        }j                         D ci c]&  \  }}|t        |j                  |j                        ( }}} |i |2 3 d {   }| c c}}w 7 6 y w)Nc              3  \   K   | ]$  }t        |j                  |j                         & y wr)   rF   r?   s     r#   r1   z&depends.<locals>.cb.<locals>.<genexpr>   rJ   rK   rL   rN   s	         r#   rR   zdepends.<locals>.cb~   sk     MMLNHHJWJ&!SaCHH!==J
W!%t!:z!: #I X!:s4   A/+A%A/A-A+A-A/+A--A/c            	        K   d D        }j                         D ci c]&  \  }}|t        |j                  |j                        ( }}} |i | d {    y c c}}w 7 w)Nc              3  \   K   | ]$  }t        |j                  |j                         & y wr)   rF   r?   s     r#   r1   z&depends.<locals>.cb.<locals>.<genexpr>   rJ   rK   rL   rO   r4   rP   r@   rQ   r   r6   r   s        r#   rR   zdepends.<locals>.cb   s_     MMLNHHJWJ&!SaCHH!==J
WD/J/// X/s   A'+AA'A%A'c            	         d D        }j                         D ci c]&  \  }}|t        |j                  |j                        ( }}} |i |S c c}}w )Nc              3  \   K   | ]$  }t        |j                  |j                         & y wr)   rF   r?   s     r#   r1   z&depends.<locals>.cb.<locals>.<genexpr>   rJ   rK   rL   rW   s        r#   rR   zdepends.<locals>.cb   sU    MMLNHHJWJ&!SaCHH!==J
WT0Z00 Xs   +Ar   )r   r   r   r   )tuplerM   r   inspectisgeneratorfunctionr   isasyncgenfunctionr   listvaluesr>   rC   hasattrr   
ValueErrortyper   rH   r   r   anyAssertionErrorr   idappendparamr   rI   rG   updater&   )r6   r   r   r   r   keyr0   r7   depsstring_specsr@   rH   rR   groupedgroupr&   s   `  ``           r#   r*   r*   (   s   0 	?,??79xxzBz83!#&	&zB L"
 ""4(	t	 
	 
	#	#D	)	t	 
	 
T	"	t	+ 
	+ 
t	% 
	% d299;//DLc3LS(#C+ A "#Y//0 1 1 SYY6cii)?@!ii/FZ$syy/BZBZ5ZE 1389 : : " 	7$771D11 - . 	.
 
" 3 4 	4 E&&t,
 ''-
 !&0
1
 d#CBsyyM"))#. ^^%E!HNN  &&r+FCHH+FG & T8R(F
MM<eA B HOOs 	Cb ,Gs   LL)r   rC   r   r   r   r   return-Callable[[CallableT], DependsFunc[CallableT]])
r   r   r   r   r   r   r   r   rn   ro   )r6   r   r   
Dependencyr   r   r   r   r   r   rn   ro   )
__future__r   r[   collectionsr   	functoolsr   typingr   r   r   r	   r
   r   parameterizedr   r   r   r   _utilsr   r   r   rC   rp   r   r%   r*   r!   r"   r#   <module>rw      s'   "  #  R R  :84ISJ hy)  
&)3#482 

 
,/%):>LU2 

 AFX]q
q'1q:>qQUqenq2q qr"   