o
    h                     @  sh   d dl mZ d dlmZ d dlmZ d dlmZ edZG dd dee Z	G dd	 d	Z
dddZdS )    )annotations)deque)islice)TypeVar_Tc                   @  s,   e Zd ZdZed
ddZedddZd	S )_Dependencyz5A class representing a (doubly-ended) queue of items.return	_T | Nonec                 C  s    z| d W S  t y   Y dS w )zHead of the dependency.r   N)
IndexErrorself r   Z/var/www/html/openai_agents/venv/lib/python3.10/site-packages/griffe/_internal/c3linear.pyhead   s
   
z_Dependency.headr   c              	   C  s6   z	t | d|  W S  ttfy   t g dd Y S w )zwTail of the dependency.

        The `islice` object is sufficient for iteration or testing membership (`in`).
           r   )r   __len__
ValueErrorr
   r   r   r   r   tail   s
   z_Dependency.tailN)r   r	   )r   r   )__name__
__module____qualname____doc__propertyr   r   r   r   r   r   r      s    r   c                   @  sl   e Zd ZdZdddZdddZdddZd ddZed!ddZ	ed"ddZ
ed#ddZd$ddZdS )%_DependencyListzA class representing a list of linearizations (dependencies).

    The last element of DependencyList is a list of parents.
    It's needed  to the merge process preserves the local
    precedence order of direct parent classes.
    listslist[_T | None]r   Nonec                 G  s   dd |D | _ dS )zVInitialize the list.

        Parameters:
            *lists: Lists of items.
        c                 S  s   g | ]}t |qS r   )r   .0lstr   r   r   
<listcomp>6   s    z,_DependencyList.__init__.<locals>.<listcomp>N_lists)r   r   r   r   r   __init__0   s   z_DependencyList.__init__itemr   boolc                   s   t  fdd| jD S )z9Return True if any linearization's tail contains an item.c                 3  s    | ]} |j v V  qd S N)r   r   r$   r   r   	<genexpr>:   s    z/_DependencyList.__contains__.<locals>.<genexpr>)anyr"   )r   r$   r   r'   r   __contains__8   s   z_DependencyList.__contains__intc                 C  s   t | j}|r|d S dS )Nr   r   )lenr"   )r   sizer   r   r   r   <   s   
z_DependencyList.__len__strc                 C  s
   | j  S r&   )r"   __repr__r   r   r   r   r/   @   s   
z_DependencyList.__repr__c                 C  s   dd | j D S )zReturn the heads.c                 S  s   g | ]}|j qS r   )r   r   r   r   r   r    F   s    z)_DependencyList.heads.<locals>.<listcomp>r!   r   r   r   r   headsC   s   z_DependencyList.headsc                 C  s   | S )z3Return self so that `__contains__` could be called.r   r   r   r   r   tailsH   s   z_DependencyList.tailsc                 C  s   t dd | jD S )z0True if all elements of the lists are exhausted.c                 s  s    | ]	}t |d kV  qdS )r   N)r,   )r   xr   r   r   r(   P   s    z,_DependencyList.exhausted.<locals>.<genexpr>)allr"   r   r   r   r   	exhaustedM   s   z_DependencyList.exhaustedr	   c                 C  s&   | j D ]}|r|j|kr|  qdS )zRemove an item from the lists.

        Once an item removed from heads, the leftmost elements of the tails
        get promoted to become the new heads.
        N)r"   r   popleft)r   r$   ir   r   r   removeR   s
   
z_DependencyList.removeN)r   r   r   r   )r$   r   r   r%   )r   r+   )r   r.   )r   r   )r   r   )r   r%   )r$   r	   r   r   )r   r   r   r   r#   r*   r   r/   r   r0   r1   r4   r7   r   r   r   r   r   (   s    



r   r   list[_T]r   c                  G  sT   g }t |  }	 |jr|S |jD ]}|r$||jvr$|| ||  nqtdq)zMerge lists of lists in the order defined by the C3Linear algorithm.

    Parameters:
        *lists: Lists of items.

    Returns:
        The merged list of items.
    TzCannot compute C3 linearization)r   r4   r0   r1   appendr7   r   )r   resultlinearizationsr   r   r   r   c3linear_merge]   s   	


r<   N)r   r8   r   r8   )
__future__r   collectionsr   	itertoolsr   typingr   r   r   r   r<   r   r   r   r   <module>   s   5