3
tûœ]k  ã               @   sD   d Z ddlZddlZddlmZ dd„ Zdd„ Zdd	„ Zd
d„ ZdS )a¯  Contains logic for retrieving special methods.

This implementation does not rely on the dot attribute access
logic, found in ``.getattr()``. The difference between these two
is that the dunder methods are looked with the type slots
(you can find more about these here
http://lucumr.pocoo.org/2014/8/16/the-python-i-would-like-to-see/)
As such, the lookup for the special methods is actually simpler than
the dot attribute access.
é    N)Ú
exceptionsc                sV   | j jˆ g ƒ}tjj‡ fdd„| jdd�D ƒƒ}ttj||ƒƒ}|sRtjˆ | d�‚|S )Nc             3   s   | ]}|j jˆ g ƒV  qd S )N)ÚlocalsÚget)Ú.0Zancestor)Úname© úD/tmp/pip-build-fn42xldr/astroid/astroid/interpreter/dunder_lookup.pyú	<genexpr>   s    z!_lookup_in_mro.<locals>.<genexpr>T)Zrecurs)Ú	attributeÚtarget)	r   r   Ú	itertoolsÚchainÚfrom_iterableZ	ancestorsÚlistr   ÚAttributeInferenceError)Únoder   ÚattrsZnodesÚvaluesr   )r   r   Ú_lookup_in_mro   s    r   c             C   sf   t | tjtjtjtjtjfƒr(t| |ƒS t | tjƒr>t	| |ƒS t | tj
ƒrTt| |ƒS tj|| d�‚dS )zÛLookup the given special method name in the given *node*

    If the special method was found, then a list of attributes
    will be returned. Otherwise, `astroid.AttributeInferenceError`
    is going to be raised.
    )r
   r   N)Ú
isinstanceÚastroidÚListÚTupleZConstÚDictÚSetÚ_builtin_lookupZInstancer   ÚClassDefÚ_class_lookupr   r   )r   r   r   r   r   Úlookup"   s    


r   c             C   s(   | j ƒ }|d krtj|| d�‚t||ƒS )N)r
   r   )Ú	metaclassr   r   r   )r   r   r   r   r   r   r   5   s    r   c             C   s$   | j j|g ƒ}|s tj|| d�‚|S )N)r
   r   )r   r   r   r   )r   r   r   r   r   r   r   =   s    r   )Ú__doc__r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   