B
    ddE  γ               @   s`   d dl mZmZ G dd deZdd Zdd Zdd	 Zd
d Zdd Z	e
fddZdd ZdS )ι   )Ϊ	_toposortΪgroupbyc               @   s   e Zd ZdS )ΪAmbiguityWarningN)Ϊ__name__Ϊ
__module__Ϊ__qualname__© r   r   ϊl/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sympy/multipledispatch/conflict.pyr      s   r   c             C   s    t | t |kottt| |S )z3 A is consistent and strictly more specific than B )ΪlenΪallΪmapΪ
issubclass)ΪaΪbr   r   r	   Ϊ
supercedes   s    r   c             C   s(   t | t |ko&tdd t| |D S )z= It is possible for an argument list to satisfy both A and B c             s   s&   | ]\}}t ||pt ||V  qd S )N)r   )Ϊ.0ZaaZbbr   r   r	   ϊ	<genexpr>   s   zconsistent.<locals>.<genexpr>)r
   r   Ϊzip)r   r   r   r   r	   Ϊ
consistent   s    r   c             C   s    t | |ot| |pt||  S )z> A is consistent with B but neither is strictly more specific )r   r   )r   r   r   r   r	   Ϊ	ambiguous   s    r   c                s    t tt   fdd D S )z5 All signature pairs such that A is ambiguous with B c                sP   h | ]H D ]>t  t k rt rt fd dD s fqqS )c             3   s"   | ]}t | ot |V  qd S )N)r   )r   Ϊc)r   r   r   r	   r      s   z(ambiguities.<locals>.<setcomp>.<genexpr>)Ϊhashr   Ϊany)r   )Ϊ
signatures)r   r   r	   ϊ	<setcomp>   s
    

zambiguities.<locals>.<setcomp>)Ϊlistr   Ϊtuple)r   r   )r   r	   Ϊambiguities   s    r   c                s<   t d  t fddD s&tfddt D S )z* A signature that would break ambiguities ι    c             3   s   | ]}t | kV  qd S )N)r
   )r   Ϊs)Ϊnr   r	   r   %   s    z"super_signature.<locals>.<genexpr>c                s*   g | ]" t  fd dD tdd qS )c                s   g | ]}t  |  ‘qS r   )ΪtypeΪmro)r   Ϊsig)Ϊir   r	   ϊ
<listcomp>'   s    z.super_signature.<locals>.<listcomp>.<listcomp>)Ϊkeyr   )Ϊmaxr
   )r   )r   )r$   r	   r%   '   s   z#super_signature.<locals>.<listcomp>)r
   r   ΪAssertionErrorΪrange)r   r   )r    r   r	   Ϊsuper_signature"   s    
r*   c             C   s,   t | |r(t || r$|| ||kS dS dS )zW A should be checked before B

    Tie broken by tie_breaker, defaults to ``hash``
    TF)r   )r   r   Ztie_breakerr   r   r	   Ϊedge+   s
    

r+   c                sf   t tt   fdd D }tdd |}x D ]}||kr4g ||< q4W dd | ‘ D }t|S )z A sane ordering of signatures to check, first to last

    Topoological sort of edges as given by ``edge`` and ``supercedes``
    c                s(   g | ] } D ]}t ||r||fqqS r   )r+   )r   r   r   )r   r   r	   r%   >   s    zordering.<locals>.<listcomp>c             S   s   | d S )Nr   r   )Ϊxr   r   r	   Ϊ<lambda>?   σ    zordering.<locals>.<lambda>c             S   s    i | ]\}}d d |D |qS )c             S   s   g | ]\}}|qS r   r   )r   r   r   r   r   r	   r%   C   s    z'ordering.<locals>.<dictcomp>.<listcomp>r   )r   ΪkΪvr   r   r	   ϊ
<dictcomp>C   s    zordering.<locals>.<dictcomp>)r   r   r   r   Ϊitemsr   )r   Ϊedgesr   r   )r   r	   Ϊordering8   s    
r4   N)Ϊutilsr   r   ΪWarningr   r   r   r   r   r*   r   r+   r4   r   r   r   r	   Ϊ<module>   s   
	