3
tûœ]Ã  ã               @   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)Ú
exceptionsc               @   s(   e Zd ZdZejdd„ ƒZddd„ZdS )ÚBlockRangeMixInzoverride block range c             C   s   | j S )N)Úlineno)Úself© r   ú1/tmp/pip-build-fn42xldr/astroid/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   | j ƒ |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_type4   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   9   s    zAssignTypeMixin.assign_typec             C   s.   | |kr|dfS | j ƒ |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   8   s   r   c               @   s   e Zd Zdd„ ZdS )ÚParentAssignTypeMixinc             C   s
   | j jƒ S )N)Úparentr   )r   r   r   r   r   H   s    z!ParentAssignTypeMixin.assign_typeN)r   r   r   r   r   r   r   r   r   G   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_nameO   s    zImportFromMixin._infer_nameNc             C   sP   | j ƒ }t| ddƒ}|dkr"| j}|j||ƒ|jkr8|S |j|||oJ|dkd�S )zOreturn 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_moduleR   s    z ImportFromMixin.do_import_modulec             C   sX   xB| j D ]8\}}|dkr|S |s4|jddƒd }|}||kr|S qW tj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   ZAttributeInferenceError)r   Zasnamer    Z_asnamer   r   r   Ú	real_nameg   s    zImportFromMixin.real_name)N)r   r   r   r   r!   r'   r.   r   r   r   r   r   L   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|jƒ 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|jƒ 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j|ƒƒS )Nc             s   s    | ]}|D ]}|j ƒ 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/   x   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   f E d H  d S )Nr   )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   r   r   r   r   r   r   r/   r?   r   r   r   r   Ú<module>   s   ,$