
    g                    |    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ee         Z	 G d d	      Z
dd
Zy)    )annotations)deque)islice)TypeVar_Tc                  4    e Zd ZdZedd       Zedd       Zy)_Dependencyz5A class representing a (doubly-ended) queue of items.c                ,    	 | d   S # t         $ r Y yw xY w)zHead of the dependency.r   N)
IndexErrorselfs    E/var/www/openai/venv/lib/python3.12/site-packages/_griffe/c3linear.pyheadz_Dependency.head   s"    	7N 		s    	c                ~    	 t        | d| j                               S # t        t        f$ r t        g dd      cY S w xY w)zwTail of the dependency.

        The `islice` object is sufficient for iteration or testing membership (`in`).
           r   )r   __len__
ValueErrorr   r   s    r   tailz_Dependency.tail   s?    	$$4<<>22J' 	$"a##	$s    <<N)return	_T | None)r   r   )__name__
__module____qualname____doc__propertyr   r        r   r	   r	      s+    ?  $ $r   r	   c                  n    e Zd ZdZddZddZddZddZedd       Z	edd       Z
edd       Zdd	Zy
)_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.
    c                J    |D cg c]  }t        |       c}| _        yc c}w )zVInitialize the list.

        Parameters:
            *lists: Lists of items.
        N)r	   _lists)r   listslsts      r   __init__z_DependencyList.__init__0   s"     4995C{3'599s    c                @    t        fd| j                  D              S )z9Return True if any linearization's tail contains an item.c              3  :   K   | ]  }|j                   v   y wN)r   ).0r#   items     r   	<genexpr>z/_DependencyList.__contains__.<locals>.<genexpr>:   s     ;{4388#{s   )anyr!   )r   r)   s    `r   __contains__z_DependencyList.__contains__8   s    ;t{{;;;r   c                >    t        | j                        }|r|dz
  S dS )Nr   r   )lenr!   )r   sizes     r   r   z_DependencyList.__len__<   s!    4;;!q(q(r   c                6    | j                   j                         S r'   )r!   __repr__r   s    r   r1   z_DependencyList.__repr__@   s    {{##%%r   c                T    | j                   D cg c]  }|j                   c}S c c}w )zReturn the heads.)r!   r   )r   r#   s     r   headsz_DependencyList.headsC   s$     %)KK0KSK000s   %c                    | S )z3Return self so that `__contains__` could be called.r   r   s    r   tailsz_DependencyList.tailsH   s	     r   c                :    t        d | j                  D              S )z0True if all elements of the lists are exhausted.c              3  8   K   | ]  }t        |      d k(    yw)r   N)r.   )r(   xs     r   r*   z,_DependencyList.exhausted.<locals>.<genexpr>P   s     413q6Q;s   )allr!   r   s    r   	exhaustedz_DependencyList.exhaustedM   s     4444r   c                l    | j                   D ]%  }|s|j                  |k(  s|j                          ' y)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)   is      r   removez_DependencyList.removeR   s(     AQVVt^		 r   N)r"   list[_T | None]r   None)r)   r   r   bool)r   int)r   str)r   r?   )r   r   )r   rA   )r)   r   r   r@   )r   r   r   r   r$   r,   r   r1   r   r3   r5   r:   r>   r   r   r   r   r   (   s\    :<)& 1 1   5 5r   r   c                     g }t        |  }	 |j                  r|S |j                  D ]7  }|s||j                  vs|j	                  |       |j                  |        n t        d      `)zMerge lists of lists in the order defined by the C3Linear algorithm.

    Parameters:
        *lists: Lists of items.

    Returns:
        The merged list of items.
    zCannot compute C3 linearization)r   r:   r3   r5   appendr>   r   )r"   resultlinearizationsr   s       r   c3linear_mergerH   ]   sv     F$e,N
##M"((D^%9%99d#%%d+  ) >?? r   N)r"   list[_T]r   rI   )
__future__r   collectionsr   	itertoolsr   typingr   r   r	   r   rH   r   r   r   <module>rN      s=    #   T]$%) $.2 2j@r   