a
    ¦ˆc|  ã                   @   s   G d d„ dƒZ dS )c                   @   s:   e Zd ZdZdZddœdd„Zdd„ Zd	d
„ Zdd„ ZdS )ÚObserverGraphak   An ``ObserverGraph`` is an object for describing what traits are being
    observed on an instance of ``HasTraits``.

    The most basic unit in a graph is a node, which is a context specific
    observer. For example, a node can be an observer specialized in
    changes on a named trait, an observer specialized in
    changes on a number of traits matching a certain criteria, an observer
    specialized in mutations on a list, etc.

    The most basic example is an ``ObserverGraph`` that contains only one node,
    e.g. for observing changes on a named trait.

    An ``ObserverGraph`` can have branches, e.g. to observe more than one trait
    on a nested object. The attribute ``children`` represents these branches.
    Each item in ``children`` is another ``ObserverGraph``.

    In order to (1) avoid hooking up a user callback with the same observer
    twice, and (2) remove an observer when they are not needed, once an
    ``ObserverGraph`` object is constructed (e.g. after mutating ``children``
    for constructing branches) and is ready to be used against an instance
    of ``HasTraits``, it should not be mutated again.

    For the same reason, ``ObserverGraph`` implements ``__hash__`` and
    ``__eq__`` and requires its nodes to also support these methods.

    An ``ObserverGraph`` does not keep states regarding the HasTraits instances
    and the user callbacks it was used with. An ``ObserverGraph`` can be
    reused multiple times on different ``HasTraits`` instance and with
    different user callback.

    This object is considered a low-level object for the observer mechanism.
    It is not intended to be instantiated by users directly. Users will be
    given higher-level wrappers for creating ``ObserverGraph`` objects.

    Parameters
    ----------
    node : any
        A context specific observer.
        It must be a hashable object. In practice, this will be
        an instance that implements ``IObserver``.
    children : iterable of ObserverGraph, optional
        Branches on this graph. All children must be unique.

    Raises
    ------
    ValueError
        If not all children are unique.
    )ÚnodeÚchildrenN)r   c                C   sD   |d ur$t t|ƒƒt |ƒkr$tdƒ‚|| _|d ur:t|ƒng | _d S )NzNot all children are unique.)ÚlenÚsetÚ
ValueErrorr   Úlistr   )Úselfr   r   © r	   úe/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/observation/_observer_graph.pyÚ__init__@   s    zObserverGraph.__init__c                 C   s   t t| ƒj| jt| jƒfƒS )z' Return the hash of this ObserverGraph.)ÚhashÚtypeÚ__name__r   Ú	frozensetr   )r   r	   r	   r
   Ú__hash__H   s    ÿzObserverGraph.__hash__c                 C   s0   t | ƒt |ƒu o.| j|jko.t| jƒt|jƒkS )z¥ Return true if another object is an ObserverGraph with the
        same content. The order of children is not taken into account
        in the comparison.
        )r   r   r   r   )r   Úotherr	   r	   r
   Ú__eq__N   s
    
ÿýzObserverGraph.__eq__c                 C   s@   d| j ›�g}| jr&| d| j›�¡ | jj› dd |¡› d�S )Nznode=z	children=ú(z, ú))r   r   ÚappendÚ	__class__r   Újoin)r   Zformatted_argsr	   r	   r
   Ú__repr__Y   s    zObserverGraph.__repr__)	r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r	   r	   r	   r
   r      s   1r   N)r   r	   r	   r	   r
   Ú<module>   ó    