a
    gDfi                     @   s`   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	 ddl
mZmZ edddd	d
ZdS )    N)defaultdict)wraps   )	ParameterParameterizedParameterizedMetaclasstransform_reference)accept_argumentsiscoroutinefunctionF)watchon_initc                   sr  t dd  D dd  D   trFtfdd}nRtrftfdd}n2trtfdd}ntfd	d}t t  }d
}|D ]}t	|t
rd}qt|drqt	|tstdt|j qt	|jtst	|jts|jdu rdndt|jj }	td|	 qtdd |D rjtdd |D rjtdn|r~r~td|sH|rHtr fdd}
nJtrƇ fdd}
n,tr fdd}
n fdd}
tt}|D ]}|t|j | q| D ]$}|d jj|
dd |D  q"tdi }| ||d ||_|S )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                 s   s   | ]}t |V  qd S Nr   ).0arg r   Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/param/depends.py	<genexpr>        zdepends.<locals>.<genexpr>c                 S   s   i | ]\}}|t |qS r   r   )r   keyr   r   r   r   
<dictcomp>!   r   zdepends.<locals>.<dictcomp>c                  ?   s    | i |D ]
}|V  qd S r   r   argskwvalfuncr   r   _depends%   s    zdepends.<locals>._dependsc                    s(    | i |2 z3 d H W }|V  q6 d S r   r   r   r   r   r   r   *   s    c                     s    | i |I d H S r   r   r   r   r   r   r   r   /   s    c                     s    | i |S r   r   r   r   r   r   r   3   s    FT_dinfozvThe depends decorator only accepts string types referencing a parameter or parameter instances, found %s type instead.NNonez%s classziParameters supplied to the depends decorator, must be bound to a Parameterized class or instance, not %s.c                 s   s   | ]}t |tV  qd S r   )
isinstancer   r   depr   r   r   r   J   r   c                 s   s   | ]}t |tV  qd S r   )r!   strr"   r   r   r   r   K   r   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   s>   dd  D }dd   D }|i |D ]
}|V  q.d S )Nc                 s   s   | ]}t |j|jV  qd S r   getattrownernamer"   r   r   r   r   Y   r   &depends.<locals>.cb.<locals>.<genexpr>c                 S   s    i | ]\}}|t |j|jqS r   r%   r   nr#   r   r   r   r   Z   r   'depends.<locals>.cb.<locals>.<dictcomp>itemseventsr   
dep_kwargsr   dependenciesr   r   r   r   cbX   s    zdepends.<locals>.cbc                    sH   dd  D }dd   D }|i |2 z3 d H W }|V  q.6 d S )Nc                 s   s   | ]}t |j|jV  qd S r   r%   r"   r   r   r   r   _   r   r)   c                 S   s    i | ]\}}|t |j|jqS r   r%   r*   r   r   r   r   `   r   r,   r-   r/   r2   r   r   r4   ^   s    c                     s8   dd  D }dd   D }|i |I d H  d S )Nc                 s   s   | ]}t |j|jV  qd S r   r%   r"   r   r   r   r   e   r   r)   c                 S   s    i | ]\}}|t |j|jqS r   r%   r*   r   r   r   r   f   r   r,   r-   r0   r   r1   r2   r   r   r4   d   s    c                     s.   dd  D }dd   D }|i |S )Nc                 s   s   | ]}t |j|jV  qd S r   r%   r"   r   r   r   r   j   r   r)   c                 S   s    i | ]\}}|t |j|jqS r   r%   r*   r   r   r   r   k   r   r,   r-   r5   r2   r   r   r4   i   s    r   c                 S   s   g | ]
}|j qS r   )r(   r"   r   r   r   
<listcomp>r   r   zdepends.<locals>.<listcomp>)r3   r   r   r   )tupler.   inspectisgeneratorfunctionr   isasyncgenfunctionr
   listvaluesr!   r$   hasattrr   
ValueErrortype__name__r'   r   r   anyAssertionErrorr   idappendparamr   r&   updater   )r   r   r   r3   r   r   depsZstring_specsr#   r'   r4   Zgroupedgroupr   r   r2   r   depends   sr    





 

"rI   )r8   collectionsr   	functoolsr   Zparameterizedr   r   r   r   _utilsr	   r
   rI   r   r   r   r   <module>   s   