o
    à8VaE  ã                   @   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   úA/usr/lib/python3/dist-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   ó    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   Úzipr   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	   Ú	ambiguous   r   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 | ]$‰ ˆ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 r   ©r   )r   Úcr   r   r	   r      s   € ÿz(ambiguities.<locals>.<setcomp>.<genexpr>)Úhashr   Úany©r   ©Ú
signaturesr   r	   Ú	<setcomp>   s    ÿþÿýzambiguities.<locals>.<setcomp>)Úlistr   Útupler   r   r   r	   Úambiguities   s   r#   c                    s<   t ˆd ƒ‰ t‡ fdd„ˆD ƒƒsJ ‚‡fdd„tˆ ƒD ƒS )z* A signature that would break ambiguities é    c                 3   s    | ]	}t |ƒˆ kV  qd S r   )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   Z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   Úranger   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``
    TFr   )r   r   Ztie_breakerr   r   r	   Úedge+   s
   

r0   c                    sb   t ttˆ ƒƒ‰ ‡ fdd„ˆ D ƒ}tdd„ |ƒ}ˆ D ]
}||vr#g ||< q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   )r0   ©r   r   r   r   r   r	   r+   >   s   ( zordering.<locals>.<listcomp>c                 S   s   | d S )Nr$   r   )Úxr   r   r	   Ú<lambda>?   s    zordering.<locals>.<lambda>c                 S   s    i | ]\}}|d d„ |D ƒ“qS )c                 S   s   g | ]\}}|‘qS r   r   r1   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   Zedgesr%   r   r   r	   Úordering8   s   €r8   N)Zutilsr   r   ÚWarningr   r   r   r   r#   r/   r   r0   r8   r   r   r   r	   Ú<module>   s    
	