B
    a                 @   s   d Z ddlZddlmZ ddlmZ G dd dZG dd dZG d	d
 d
ZG dd deZ	G dd deZ
G dd dZG dd dZdS )z:This module contains some mixins for the different nodes.
    N)
decorators)AttributeInferenceErrorc               @   s(   e Zd ZdZejdd ZdddZdS )BlockRangeMixInzoverride block rangec             C   s   | j S )N)lineno)self r   2/tmp/pip-unpacked-wheel-mm06h1t3/astroid/mixins.pyblockstart_tolineno   s    z#BlockRangeMixIn.blockstart_tolinenoNc             C   sR   || j kr||fS |rD||d j kr2||d jfS ||d j d fS ||pN| jfS )z^handle block line numbers range for try/finally, for, if and while
        statements
        r      )Z
fromlinenoZtolineno)r   r   Zorelselastr   r   r   _elsed_block_range   s    
z"BlockRangeMixIn._elsed_block_range)N)__name__
__module____qualname____doc__r   cachedpropertyr	   r   r   r   r   r   r      s   r   c               @   s    e Zd ZdZdd Zdd ZdS )FilterStmtsMixinz1Mixin for statement filtering and assignment typec             C   s   |   |kr|gdfS |dfS )z@method used in _filter_stmts to get statements and trigger breakTF)	statement)r   _node_stmtsmystmtr   r   r   _get_filtered_stmts/   s    
z$FilterStmtsMixin._get_filtered_stmtsc             C   s   | S )Nr   )r   r   r   r   assign_type7   s    zFilterStmtsMixin.assign_typeN)r   r   r   r   r   r   r   r   r   r   r   ,   s   r   c               @   s   e Zd Zdd Zdd ZdS )AssignTypeMixinc             C   s   | S )Nr   )r   r   r   r   r   <   s    zAssignTypeMixin.assign_typec             C   s.   | |kr|dfS |   |kr&|gdfS |dfS )zmethod used in filter_stmtsTF)r   )r   Zlookup_noder   r   r   r   r   r   r   ?   s
    
z#AssignTypeMixin._get_filtered_stmtsN)r   r   r   r   r   r   r   r   r   r   ;   s   r   c               @   s   e Zd Zdd ZdS )ParentAssignTypeMixinc             C   s
   | j  S )N)parentr   )r   r   r   r   r   K   s    z!ParentAssignTypeMixin.assign_typeN)r   r   r   r   r   r   r   r   r   J   s   r   c               @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
ImportFromMixinzMixIn for From and Import Nodesc             C   s   |S )Nr   )r   framenamer   r   r   _infer_nameR   s    zImportFromMixin._infer_nameNc             C   sP   |   }t| dd}|dkr"| j}||||jkr8|S |j|||oJ|dkdS )zFreturn the ast for a module whose name is <modname> imported by <self>levelNr   )r"   Zrelative_only)rootgetattrmodnameZrelative_to_absolute_namer    import_module)r   r%   Zmymoduler"   r   r   r   do_import_moduleU   s    z ImportFromMixin.do_import_modulec             C   sV   xB| j D ]8\}}|dkr|S |s4|ddd }|}||kr|S qW td| |ddS )zget name from 'as' name*.r   r   z:Could not find original name for {attribute} in {target!r})target	attributeN)namessplitr   )r   Zasnamer    Z_asnamer   r   r   	real_namei   s    zImportFromMixin.real_name)N)r   r   r   r   r!   r'   r.   r   r   r   r   r   O   s   
r   c               @   s<   e Zd ZdZejdd Zdd Zdd Zej	dd	 Z
d
S )MultiLineBlockMixina.  Mixin for nodes with multi-line blocks, e.g. For and FunctionDef.
    Note that this does not apply to every node with a `body` field.
    For instance, an If node has a multi-line body, but the body of an
    IfExpr is not multi-line, and hence cannot contain Return nodes,
    Assign nodes, etc.
    c                s   t  fdd jD S )Nc             3   s   | ]}t  |V  qd S )N)r$   ).0field)r   r   r   	<genexpr>   s    z9MultiLineBlockMixin._multi_line_blocks.<locals>.<genexpr>)tupleZ_multi_line_block_fields)r   r   )r   r   _multi_line_blocks   s    z&MultiLineBlockMixin._multi_line_blocksc             c   s8   x2| j D ](}x"|D ]}|jrq| E d H  qW qW d S )N)r4   Zis_function _get_return_nodes_skip_functions)r   block
child_noder   r   r   r5      s
    
z4MultiLineBlockMixin._get_return_nodes_skip_functionsc             c   s8   x2| j D ](}x"|D ]}|jrq| E d H  qW qW d S )N)r4   Z	is_lambda_get_yield_nodes_skip_lambdas)r   r6   r7   r   r   r   r8      s
    
z1MultiLineBlockMixin._get_yield_nodes_skip_lambdasc             C   s    dd | j D }ttj|S )Nc             s   s    | ]}|D ]}|  V  q
qd S )N)_get_assign_nodes)r0   r6   r7   r   r   r   r2      s   z8MultiLineBlockMixin._get_assign_nodes.<locals>.<genexpr>)r4   list	itertoolschainfrom_iterable)r   Zchildren_assign_nodesr   r   r   r9      s    
z%MultiLineBlockMixin._get_assign_nodesN)r   r   r   r   r   r   r4   r5   r8   cachedr9   r   r   r   r   r/   z   s
   r/   c               @   s   e Zd ZdZdd ZdS )NoChildrenMixinz,Mixin for nodes with no children, e.g. Pass.c             c   s   dE d H  d S )Nr   r   )r   r   r   r   get_children   s    zNoChildrenMixin.get_childrenN)r   r   r   r   r@   r   r   r   r   r?      s   r?   )r   r;   Zastroidr   Zastroid.exceptionsr   r   r   r   r   r   r/   r?   r   r   r   r   <module>   s   +$