o
    b                     @   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	   M/var/www/secure340b-portal/env/lib/python3.10/site-packages/astroid/mixins.pyblockstart_tolineno   s   z#BlockRangeMixIn.blockstart_tolinenoNc                 C   sR   || j kr	||fS |r"||d j kr||d jfS ||d j d fS ||p'| jfS )z^handle block line numbers range for try/finally, for, if and while
        statements
        r      )Z
fromlinenoZtolineno)r   r   orelselastr	   r	   r
   _elsed_block_range   s   
z"BlockRangeMixIn._elsed_block_ranger   )__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   |   |u r|gdfS |dfS )z@method used in _filter_stmts to get statements and trigger breakTFZ	statement)r   _node_stmtsmystmtr	   r	   r
   _get_filtered_stmts,   s   
z$FilterStmtsMixin._get_filtered_stmtsc                 C      | S r   r	   r   r	   r	   r
   assign_type4      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   r   r   r	   r   r	   r	   r
   r   9   r   zAssignTypeMixin.assign_typec                 C   s.   | |u r|dfS |   |u r|gdfS |dfS )zmethod used in filter_stmtsTFr   )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  S r   )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 r   r	   )r   framenamer	   r	   r
   _infer_nameO   r   zImportFromMixin._infer_nameNc                 C   sP   |   }t| dd}|du r| j}||||jkr|S |j|||o%|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   | j D ] \}}|dkr|  S |s|ddd }|}||kr#|  S qtjd| |d)zget name from 'as' name*.r   r   z:Could not find original name for {attribute} in {target!r})target	attribute)namessplitr   ZAttributeInferenceError)r   asnamer%   Z_asnamer	   r	   r
   	real_nameg   s   zImportFromMixin.real_namer   )r   r   r   r   r&   r,   r4   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 r   )r)   ).0fieldr   r	   r
   	<genexpr>   s    z9MultiLineBlockMixin._multi_line_blocks.<locals>.<genexpr>)tupleZ_multi_line_block_fieldsr   r	   r   r
   _multi_line_blocks   s   z&MultiLineBlockMixin._multi_line_blocksc                 c   2    | j D ]}|D ]}|jrq| E d H  qqd S r   )r:   Zis_function _get_return_nodes_skip_functionsr   block
child_noder	   r	   r
   r<         
z4MultiLineBlockMixin._get_return_nodes_skip_functionsc                 c   r;   r   )r:   Z	is_lambda_get_yield_nodes_skip_lambdasr=   r	   r	   r
   rA      r@   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 r   )_get_assign_nodes)r6   r>   r?   r	   r	   r
   r8      s    z8MultiLineBlockMixin._get_assign_nodes.<locals>.<genexpr>)r:   list	itertoolschainfrom_iterable)r   Zchildren_assign_nodesr	   r	   r
   rB      s   z%MultiLineBlockMixin._get_assign_nodesN)r   r   r   r   r   r   r:   r<   rA   cachedrB   r	   r	   r	   r
   r5   x   s    
r5   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   rI   r	   r	   r	   r
   rH      s    rH   )r   rD   Zastroidr   r   r   r   r    r!   r#   r5   rH   r	   r	   r	   r
   <module>   s   ,$