
    Mhj                     :   d Z ddlZ	 ddlmZ n# e$ r	 ddlmZ Y nw xY wddlmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ  eg d          Z ed	d
g          ez  Z eg d          ez  Z eg d          Z eddg          Z G d d          Z G d d          Z G d dee          Z G d de          Z G d dee
          Z G d dee	          Z G d dee          Z G d dee          Z  G d d e          Z! G d! d"e          Z" G d# d$e          Z# G d% d&e          Z$ G d' d(e$          Z% G d) d*e$          Z& G d+ d,e          Z' G d- d.e          Z( G d/ d0e          Z) G d1 d2          Z* G d3 d4ee*          Z+ G d5 d6ee*          Z, G d7 d8ee          Z- G d9 d:e-          Z. G d; d<e          Z/ G d= d>e-          Z0 G d? d@e0          Z1dA Z2 G dB dCe0          Z3 G dD dEe3          Z4 G dF dGe          Z5 G dH dIe5          Z6 G dJ dKe5          Z7 G dL dMe5          Z8 G dN dOe5          Z9 G dP dQe5          Z: G dR dSe          Z; G dT dUe;          Z< G dV dWe;          Z= G dX dYe          Z> G dZ d[e>          Z? G d\ d]e>          Z@ G d^ d_e>          ZA G d` dae          ZBdb ZC G dc ddee          ZD G de dfe          ZE G dg dhe          ZF G di dje          ZGeGZH G dk dle          ZIdS )ma  
This is the syntax tree for Python 3 syntaxes. The classes represent
syntax elements like functions and imports.

All of the nodes can be traced back to the `Python grammar file
<https://docs.python.org/3/reference/grammar.html>`_. If you want to know how
a tree is structured, just analyse that file (for each Python version it's a
bit different).

There's a lot of logic here that makes it easier for Jedi (and other libraries)
to deal with a Python syntax tree.

By using :py:meth:`parso.tree.NodeOrLeaf.get_code` on a module, you can get
back the 1-to-1 representation of the input given to the parser. This is
important if you want to refactor a parser tree.

>>> from parso import parse
>>> parser = parse('import os')
>>> module = parser.get_root_node()
>>> module
<Module: @1-1>

Any subclasses of :class:`Scope`, including :class:`Module` has an attribute
:attr:`iter_imports <Scope.iter_imports>`:

>>> list(module.iter_imports())
[<ImportName: import os@1,0>]

Changes to the Python Grammar
-----------------------------

A few things have changed when looking at Python grammar files:

- :class:`Param` does not exist in Python grammar files. It is essentially a
  part of a ``parameters`` node.  |parso| splits it up to make it easier to
  analyse parameters. However this just makes it easier to deal with the syntax
  tree, it doesn't actually change the valid syntax.
- A few nodes like `lambdef` and `lambdef_nocond` have been merged in the
  syntax tree to make it easier to do deal with them.

Parser Tree Classes
-------------------
    N)Mapping)Tuple)NodeBaseNodeLeaf	ErrorNode	ErrorLeafsearch_ancestor)split_prefix)split_lines)if_stmt
while_stmtfor_stmttry_stmt	with_stmt
async_stmtsuiter   simple_stmt)r   r   	decoratedasync_funcdef)		expr_stmtsync_comp_forr   r   import_nameimport_fromparamdel_stmtnamedexpr_testr   r   c                       e Zd ZdZd ZdS )DocstringMixin c                    | j         dk    r| j        d         }n| j         dv rA| j        | j                            d          dz            }|j         dk    r|j        d         }n7| j        }|j        j        }|                    |          }|sdS ||dz
           }|j         dk    r|j        d         }|j         d	k    r|S dS )
zN
        Returns the string leaf of a docstring. e.g. ``r'''foo'''``.
        
file_inputr   funcdefclassdef:   r   Nr   string)typechildrenindexparent)selfnoder   cr+   s        Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/parso/python/tree.pyget_doc_nodezDocstringMixin.get_doc_nodeJ   s     9$$=#DDY111=!4!4S!9!9A!=>DyG##}Q'+K"+AGGK((E tUQY<D9%%=#D9  Kt    N)__name__
__module____qualname__	__slots__r1   r    r2   r0   r   r   G   s(        I    r2   r   c                       e Zd ZdZdZd ZdS )PythonMixinz)
    Some Python specific utilities.
    r    c                     | j         D ]\}t          |t                    r*|j        dk    r|j        |cxk    r|j        k    rn <|c S A|                    |          }||c S ]dS )z
        Given a (line, column) tuple, returns a :py:class:`Name` or ``None`` if
        there is no name at that position.
        nameN)r*   
isinstancer   r)   	start_posend_posget_name_of_position)r-   positionr/   results       r0   r>   z PythonMixin.get_name_of_positioni   s    
  	" 	"A!T"" "6V##x(L(L(L(L19(L(L(L(L(LHHH//99%!MMM &tr2   N)r3   r4   r5   __doc__r6   r>   r    r2   r0   r8   r8   c   s4          I    r2   r8   c                       e Zd ZdZd Zd ZdS )
PythonLeafr    c                 F    t          | |                                           S N)r   get_start_pos_of_prefixr-   s    r0   _split_prefixzPythonLeaf._split_prefix|   s    D$">">"@"@AAAr2   c                     |                                  }|(|j        dk    r|j        dv r|                                 }|0t          | j                  }| j        t          |          z
  dz   dfS |j        S )z[
        Basically calls :py:meth:`parso.tree.NodeOrLeaf.get_start_pos_of_prefix`.
        N
error_leaf)INDENTDEDENTERROR_DEDENTr'   r   )get_previous_leafr)   
token_typer   prefixlinelenr=   )r-   previous_leafliness      r0   rF   z"PythonLeaf.get_start_pos_of_prefix   s     ..00$);|)K)K!,0TTT);;==M ,,E9s5zz)A-q00$$r2   N)r3   r4   r5   r6   rH   rF   r    r2   r0   rC   rC   y   s:        IB B B% % % % %r2   rC   c                   B    e Zd ZdZdZedeeef         fd            ZdS )_LeafWithoutNewlinesz.
    Simply here to optimize performance.
    r    returnc                 H    | j         | j        t          | j                  z   fS rE   )rQ   columnrR   valuerG   s    r0   r=   z_LeafWithoutNewlines.end_pos   s    y$+DJ777r2   N)	r3   r4   r5   rA   r6   propertyr   intr=   r    r2   r0   rV   rV      sR          I8sCx 8 8 8 X8 8 8r2   rV   c                       e Zd ZdZdS )PythonBaseNoder    Nr3   r4   r5   r6   r    r2   r0   r^   r^              IIIr2   r^   c                       e Zd ZdZdS )
PythonNoder    Nr_   r    r2   r0   rb   rb      r`   r2   rb   c                       e Zd ZdZdS )PythonErrorNoder    Nr_   r    r2   r0   rd   rd      r`   r2   rd   c                       e Zd ZdZdS )PythonErrorLeafr    Nr_   r    r2   r0   rf   rf      r`   r2   rf   c                       e Zd ZdZdZd ZdS )	EndMarkerr    	endmarkerc                 l    dt          |           j        dt          | j                  d| j        dS )N<z	: prefix=z	 end_pos=>)r)   r3   reprrP   r=   rG   s    r0   __repr__zEndMarker.__repr__   s:     JJdk!2!2!2!2DLLL
 	
r2   N)r3   r4   r5   r6   r)   rn   r    r2   r0   rh   rh      s-        ID
 
 
 
 
r2   rh   c                        e Zd ZdZdZdZd ZdS )Newlinez&Contains NEWLINE and ENDMARKER tokens.r    newlinec                 \    dt          |           j        dt          | j                  dS )Nrk   : rl   )r)   r3   rm   rZ   rG   s    r0   rn   zNewline.__repr__   s.     !$ZZ000$tz2B2B2B2BCCr2   N)r3   r4   r5   rA   r6   r)   rn   r    r2   r0   rp   rp      s8        00IDD D D D Dr2   rp   c                   0    e Zd ZdZdZdZd Zd	dZd
dZdS )Nameza
    A string. Sometimes it is important to know if the string belongs to a name
    or not.
    r:   r    c           	      b    dt          |           j        d| j        d| j        d| j        d	S )Nrk   rs   @,rl   )r)   r3   rZ   rQ   rY   rG   s    r0   rn   zName.__repr__   s9     #'::#6#6#6


#'999dkkk; 	;r2   Fc                 2    |                      |          duS )z<
        Returns True if the name is being defined.
        )include_setitemN)get_definitionr-   rz   s     r0   is_definitionzName.is_definition   s      ""?"CC4OOr2   c                 <   | j         }|j        }|dv r| |j        k    r|S dS |dk    r!|                                 dk    r|j         S dS |Q|j        dk    rdS |j        t          v r-| |                    |          v r|S |r|j        t          v r|S dS |j         }|QdS )z
        Returns None if there's no definition for a name.

        :param import_name_always: Specifies if an import name is always a
            definition. Normally foo in `from foo import bar` is not a
            definition.
        r#   Nexcept_clauseasr   )r,   r)   r:   get_previous_sibling_GET_DEFINITION_TYPESget_defined_names_IMPORTS)r-   import_name_alwaysrz   r.   type_s        r0   r{   zName.get_definition   s     {	+++ty  4O##((**d22{"4yG##ty111411/BBBBK%  $)x*?*?Kt;D  tr2   NF)FF)	r3   r4   r5   rA   r)   r6   rn   r}   r{   r    r2   r0   ru   ru      se          DI; ; ;P P P P     r2   ru   c                       e Zd ZdZdS )Literalr    Nr_   r    r2   r0   r   r      r`   r2   r   c                       e Zd ZdZdZdS )Numbernumberr    Nr3   r4   r5   r)   r6   r    r2   r0   r   r      s        DIIIr2   r   c                   2    e Zd ZdZdZed             Zd ZdS )Stringr(   r    c                 \    t          j        d| j                                      d          S )Nz\w*(?=[\'"])r   )rematchrZ   grouprG   s    r0   string_prefixzString.string_prefix  s$    x44::1===r2   c                     t          j        d| j        t           j                  }|                    d          d t          |                    d                              S )Nz('{3}|"{3}|'|")(.*)$)flags   r'   )r   searchrZ   DOTALLr   rR   )r-   r   s     r0   _get_payloadzString._get_payload  sW    	'J)
 
 

 {{1~~3EKKNN 3 33344r2   N)r3   r4   r5   r)   r6   r[   r   r   r    r2   r0   r   r      sF        DI> > X>5 5 5 5 5r2   r   c                       e Zd ZdZdZdZdS )FStringStringx
    f-strings contain f-string expressions and normal python strings. These are
    the string parts of f-strings.
    fstring_stringr    Nr3   r4   r5   rA   r)   r6   r    r2   r0   r   r     s$          DIIIr2   r   c                       e Zd ZdZdZdZdS )FStringStartr   fstring_startr    Nr   r    r2   r0   r   r     s$          DIIIr2   r   c                       e Zd ZdZdZdZdS )
FStringEndr   fstring_endr    Nr   r    r2   r0   r   r      s$          DIIIr2   r   c                       e Zd ZdZd Zd ZdS )_StringComparisonMixinr    c                 J    t          |t                    r| j        |k    S | |u S )ze
        Make comparisons with strings easy.
        Improves the readability of the parser.
        )r;   strrZ   r-   others     r0   __eq__z_StringComparisonMixin.__eq__,  s-    
 eS!! 	':&&u}r2   c                 *    t          | j                  S rE   )hashrZ   rG   s    r0   __hash__z_StringComparisonMixin.__hash__6      DJr2   N)r3   r4   r5   r6   r   r   r    r2   r0   r   r   )  s7        I           r2   r   c                       e Zd ZdZdZdS )Operatoroperatorr    Nr   r    r2   r0   r   r   :  s        DIIIr2   r   c                       e Zd ZdZdZdS )Keywordkeywordr    Nr   r    r2   r0   r   r   ?  s        DIIIr2   r   c                   J     e Zd ZdZdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
Scopez
    Super class for the parser tree, which represents the state of a python
    text file.
    A Scope is either a function, class or lambda.
    r    c                 J    t                                          |           d S rE   super__init__r-   r*   	__class__s     r0   r   zScope.__init__L  !    """""r2   c                 ,    |                      d          S )z9
        Returns a generator of `funcdef` nodes.
        r$   _search_in_scoperG   s    r0   iter_funcdefszScope.iter_funcdefsO  s     $$Y///r2   c                 ,    |                      d          S )z:
        Returns a generator of `classdef` nodes.
        r%   r   rG   s    r0   iter_classdefszScope.iter_classdefsU  s     $$Z000r2   c                 .    |                      dd          S )zO
        Returns a generator of `import_name` and `import_from` nodes.
        r   r   r   rG   s    r0   iter_importszScope.iter_imports[  s     $$]MBBBr2   c                 2    fd | j                   S )Nc              3   x   K   | D ]3}|j         v r|V  |j         t          v r |j                  E d {V  4d S rE   )r)   _FUNC_CONTAINERSr*   )r*   elementnamesscans     r0   r   z$Scope._search_in_scope.<locals>.scanb  sj      # 6 6<5((!MMM<#333#tG$4555555555	6 6r2   r*   )r-   r   r   s    `@r0   r   zScope._search_in_scopea  s6    	6 	6 	6 	6 	6 	6 tDM"""r2   c                     | j         d         S )zD
        Returns the part that is executed by the function.
        r   rG   s    r0   	get_suitezScope.get_suitek  s     }R  r2   c           	          	 | j         j        }n# t          $ r d}Y nw xY wdt          |           j        d|d| j        d         d| j        d         d	S )N rk   rs   rw   r   -rl   )r:   rZ   AttributeErrorr)   r3   r<   r=   )r-   r:   s     r0   rn   zScope.__repr__q  sy    	9?DD 	 	 	DDD	 $(::#6#6#6#'>!#4#4#4dl1oooG 	Gs    )r3   r4   r5   rA   r6   r   r   r   r   r   r   rn   __classcell__r   s   @r0   r   r   D  s         
 I# # # # #0 0 01 1 1C C C# # #! ! !G G G G G G Gr2   r   c                   6     e Zd ZdZdZdZ fdZd Zd Z xZ	S )Modulez
    The top scope, which is always a module.
    Depending on the underlying parser this may be a full module or just a part
    of a module.
    )_used_namesr"   c                 X    t                                          |           d | _        d S rE   )r   r   r   r   s     r0   r   zModule.__init__  s)    """r2   c              #      K   |                                  D ]d}|j        dk    rW|j        dk    rL|                                D ]7}d |D             }t	          |          dk    r|d         dk    r
|d         V  8edS )zU
        :return: A list of future import names.
        :rtype: list of str
        r   r   c                     g | ]	}|j         
S r    )rZ   ).0r:   s     r0   
<listcomp>z4Module._iter_future_import_names.<locals>.<listcomp>  s    999DTZ999r2   r   
__future__r'   N)r   r)   level	get_pathsrR   )r-   imppathr   s       r0   _iter_future_import_namesz Module._iter_future_import_names  s       $$&& 	' 	'Cx=((SY!^^MMOO ' 'D99D999E5zzQ58|+C+C#Ah	' 	'r2   c                 p    | j         'i fd |            t                    | _         | j         S )z
        Returns all the :class:`Name` leafs that exist in this module. This
        includes both definitions and references of names.
        Nc                     	 | j         }|D ]} |           d S # t          $ rB | j        dk    r3                    | j        g           }|                    |            Y d S Y d S w xY w)Nr:   )r*   r   r)   
setdefaultrZ   append)r.   r*   childarrdctrecurses       r0   r   z&Module.get_used_names.<locals>.recurse  s    '#}H "* ' '' ' & ) ) )yF**!nnTZ<<

4(((((( +**)s    AA('A()r   UsedNamesMapping)r-   r   r   s    @@r0   get_used_nameszModule.get_used_names  sZ    
 #C	' 	' 	' 	' 	' 	' GDMMM/44Dr2   )
r3   r4   r5   rA   r6   r)   r   r   r   r   r   s   @r0   r   r   {  sl         
 !ID         ' ' '              r2   r   c                       e Zd ZdZdZdS )	Decorator	decoratorr    Nr   r    r2   r0   r   r     s        DIIIr2   r   c                   .    e Zd ZdZed             Zd ZdS )ClassOrFuncr    c                     | j         d         S )zR
        Returns the `Name` leaf that defines the function or class name.
        r'   r   rG   s    r0   r:   zClassOrFunc.name  s    
 }Qr2   c                     | j         }|j        dk    r|j         }|j        dk    r7|j        d         j        dk    r|j        d         j        S |j        dd         S g S )z4
        :rtype: list of :class:`Decorator`
        r   r   r   
decoratorsNr'   )r,   r)   r*   )r-   r   s     r0   get_decoratorszClassOrFunc.get_decorators  sk     K	>_,,!(I>[((!!$)\99 )!,55 )"1"--Ir2   N)r3   r4   r5   r6   r[   r:   r   r    r2   r0   r   r     sA        I    X     r2   r   c                   0     e Zd ZdZdZdZ fdZd Z xZS )Classz>
    Used to store the parsed contents of a python class.
    r%   r    c                 J    t                                          |           d S rE   r   r   s     r0   r   zClass.__init__  r   r2   c                 h    | j         d         dk    rdS | j         d         dk    rdS | j         d         S )z
        Returns the `arglist` node that defines the super classes. It returns
        None if there are no arguments.
        r   (N   )r   rG   s    r0   get_super_arglistzClass.get_super_arglist  s?    
 =s""4}Q3&&t}Q''r2   )	r3   r4   r5   rA   r)   r6   r   r   r   r   s   @r0   r   r     s]          DI# # # # #( ( ( ( ( ( (r2   r   c                    	 |d         }n# t           $ r g cY S w xY w|j        dv rt          |g|           gS |dk    r|gS |j        dk    r|g}n|j        }g }d}t	          |dgz   d          D ]\  }}||dk    rz|||         }|rn|d         dk    rt          |          dk    s|d         dk    s|d         dk    r|D ]	}	| |	_        
||z  }n#|                    t          ||                      |}|S )	a  
    `argslist_list` is a list that can contain an argslist as a first item, but
    most not. It's basically the items between the parameter brackets (which is
    at most one item).
    This function modifies the parser structure. It generates `Param` objects
    from the normal ast. Those param objects do not exist in a normal ast, but
    make the evaluation of the ast tree so much easier.
    You could also say that this function replaces the argslist node with a
    list of Param objects.
    r   )r:   fpdef*tfpdefNr'   rx   /)
IndexErrorr)   Paramr*   	enumeraterR   r,   r   )
r,   argslist_listfirstr*   new_childrenstartendr   param_childrenps
             r0   _create_paramsr    sk   a    			 z&&&ugv&&''	#w:!!wHH~H#Hv$5q99 	  	 JC}!)%)!4! 
 %a(C//!$^!4!4!9!9$21$5$<$<-a0C77!/ . .A'-AHH$6$++E.&,I,IJJJEs    c                   z     e Zd ZdZdZdZ fdZd Zd Ze	d             Z
d Zd	 Zd
 Zd Ze	d             Z xZS )Functionan  
    Used to store the parsed contents of a python function.

    Children::

        0. <Keyword: def>
        1. <Name>
        2. parameter list (including open-paren and close-paren <Operator>s)
        3. or 5. <Operator: :>
        4. or 6. Node() representing function body
        3. -> (if annotation is also present)
        4. annotation (if present)
    r$   r    c                     t                                          |           | j        d         }|j        dd         }t          d |D                       st	          ||          |j        dd<   d S d S )Nr   r'   r   c              3   @   K   | ]}t          |t                    V  d S rE   r;   r  r   r   s     r0   	<genexpr>z$Function.__init__.<locals>.<genexpr>-  ,      MM:eU++MMMMMMr2   )r   r   r*   anyr  )r-   r*   
parametersparameters_childrenr   s       r0   r   zFunction.__init__'  s    """]1%
(1!B$7 MM9LMMMMM 	X(6zCV(W(WJ"%%%	X 	Xr2   c                 &    | j         d         j         S )Nr   r   rG   s    r0   _get_param_nodeszFunction._get_param_nodes0  s    }Q((r2   c                 >    d |                                  D             S )z.
        Returns a list of `Param()`.
        c                 (    g | ]}|j         d k    |S )r   )r)   )r   r  s     r0   r   z'Function.get_params.<locals>.<listcomp>7  s$    HHHaaf6G6G6G6G6Gr2   )r  rG   s    r0   
get_paramszFunction.get_params3  s%     IH40022HHHHr2   c                     | j         d         S Nr'   r   rG   s    r0   r:   zFunction.name9      }Qr2   c                 .    fd | j                   S )z6
        Returns a generator of `yield_expr`.
        c              3      K   | D ]^}|j         dv r	 |j        } |          E d {V  &# t          $ r, |j        dk    r|j        j         dk    r
|j        V  n|V  Y [w xY wd S )N)r%   r$   lambdefyield
yield_expr)r)   r*   r   rZ   r,   )r*   r   nested_childrenr   s      r0   r   z'Function.iter_yield_exprs.<locals>.scanA  s      # 5 5<#EEE	5&-&6O  $tO4444444444 & * * *}//">.,>>").0000")MMM*5 5s   ,3A"!A"r   r-   r   s    @r0   iter_yield_exprszFunction.iter_yield_exprs=  s0    	5 	5 	5 	5 	5  tDM"""r2   c                 .    fd | j                   S )z7
        Returns a generator of `return_stmt`.
        c              3      K   | D ]K}|j         dk    s|j         dk    r|j        dk    r|V  |j         t          v r |j                  E d {V  Ld S )Nreturn_stmtr   rW   r)   rZ   _RETURN_STMT_CONTAINERSr*   r*   r   r   s     r0   r   z(Function.iter_return_stmts.<locals>.scanW  s      # 6 6<=00"<944(9R9R!MMM<#:::#tG$45555555556 6r2   r   r*  s    @r0   iter_return_stmtszFunction.iter_return_stmtsS  0    	6 	6 	6 	6 	6 tDM"""r2   c                 .    fd | j                   S )zi
        Returns a generator of `raise_stmt`. Includes raise statements inside try-except blocks
        c              3      K   | D ]K}|j         dk    s|j         dk    r|j        dk    r|V  |j         t          v r |j                  E d {V  Ld S )N
raise_stmtr   raiser/  r1  s     r0   r   z'Function.iter_raise_stmts.<locals>.scane  s      # 6 6<<//"<944'9Q9Q!MMM<#:::#tG$45555555556 6r2   r   r*  s    @r0   iter_raise_stmtszFunction.iter_raise_stmtsa  r3  r2   c                 J    t          |                                 d          duS )zK
        :return bool: Checks if a function is a generator or not.
        N)nextr+  rG   s    r0   is_generatorzFunction.is_generatoro  s%     D))++T22$>>r2   c                     	 | j         d         dk    r| j         d         S | j         d         dk    sJ dS # t          $ r Y dS w xY w)zW
        Returns the test node after `->` or `None` if there is no annotation.
        r   z->   r&   N)r*   r  rG   s    r0   
annotationzFunction.annotationu  se    
	}Q4''}Q''=#s****4 	 	 	44	s   5 5 
AA)r3   r4   r5   rA   r)   r6   r   r  r   r[   r:   r+  r2  r8  r;  r>  r   r   s   @r0   r  r    s          DIX X X X X) ) )I I I     X # # #,# # ## # #? ? ? 
 
 X
 
 
 
 
r2   r  c                   b     e Zd ZdZdZdZ fdZed             Zd Z	ed             Z
d Z xZS )	Lambdaz
    Lambdas are basically trimmed functions, so give it the same interface.

    Children::

         0. <Keyword: lambda>
         *. <Param x> for each argument x
        -2. <Operator: :>
        -1. Node() representing body
    r&  r    c                     t          t          |                               |           | j        dd         }t	          d |D                       st          | |          | j        dd<   d S d S )Nr'   c              3   @   K   | ]}t          |t                    V  d S rE   r  r  s     r0   r  z"Lambda.__init__.<locals>.<genexpr>  r  r2   )r   r  r   r*   r  r  )r-   r*   r  r   s      r0   r   zLambda.__init__  s    h&&x000"mAbD1 MM9LMMMMM 	L"07J"K"KDM!B$	L 	Lr2   c                      t          d          )zN
        Raises an AttributeError. Lambdas don't have a defined name.
        zlambda is not named.)r   rG   s    r0   r:   zLambda.name  s    
 3444r2   c                      | j         dd         S )Nr'   rB  r   rG   s    r0   r  zLambda._get_param_nodes  s    }QrT""r2   c                     dS )zA
        Returns `None`, lambdas don't have annotations.
        Nr    rG   s    r0   r>  zLambda.annotation  s	    
 tr2   c                 2    d| j         j        d| j        dS )Nrk   rw   rl   )r   r3   r<   rG   s    r0   rn   zLambda.__repr__  s       N333T^^^DDr2   )r3   r4   r5   rA   r)   r6   r   r[   r:   r  r>  rn   r   r   s   @r0   r@  r@    s        	 	 DIL L L L L 5 5 X5# # #   XE E E E E E Er2   r@  c                       e Zd ZdZdS )Flowr    Nr_   r    r2   r0   rI  rI    r`   r2   rI  c                   (    e Zd ZdZdZd Zd Zd ZdS )IfStmtr   r    c              #   j   K   t          | j                  D ]\  }}|dv r| j        |dz            V  dS )z
        E.g. returns all the `test` nodes that are named as x, below:

            if x:
                pass
            elif x:
                pass
        )elififr'   N)r  r*   )r-   ir/   s      r0   get_test_nodeszIfStmt.get_test_nodes  sR       dm,, 	+ 	+DAqN""mAE****	+ 	+r2   c                     |j         }t          t          |                                                     D ]}|j         |k     r||j        k     r dS |c S  dS )z
        Searches for the branch in which the node is and returns the
        corresponding test node (see function above). However if the node is in
        the test node itself and not in the suite return None.
        N)r<   reversedlistrP  r=   )r-   r.   r<   
check_nodes       r0   get_corresponding_test_nodez"IfStmt.get_corresponding_test_node  sv     N	"4(;(;(=(=#>#>?? 	& 	&J#i//z11144 &%%% 0	& 	&r2   c                 L    | j         D ]}|dk    r|j        |j        k    r dS dS )z;
        Checks if a node is defined after `else`.
        elseTF)r*   r<   )r-   r.   r/   s      r0   is_node_after_elsezIfStmt.is_node_after_else  s:      	 	AF{{>AK//445r2   N)r3   r4   r5   r)   r6   rP  rU  rX  r    r2   r0   rK  rK    sK        DI+ + +& & & 	 	 	 	 	r2   rK  c                       e Zd ZdZdZdS )	WhileStmtr   r    Nr   r    r2   r0   rZ  rZ            DIIIr2   rZ  c                   $    e Zd ZdZdZd ZddZdS )ForStmtr   r    c                     | j         d         S )zE
        Returns the input node ``y`` from: ``for x in y:``.
        r   r   rG   s    r0   get_testlistzForStmt.get_testlist  s     }Qr2   Fc                 8    t          | j        d         |          S r"  _defined_namesr*   r|   s     r0   r   zForStmt.get_defined_names      dmA.@@@r2   Nr   )r3   r4   r5   r)   r6   r_  r   r    r2   r0   r]  r]    sG        DI     A A A A A Ar2   r]  c                       e Zd ZdZdZd ZdS )TryStmtr   r    c              #   h   K   | j         D ]'}|j        dk    r|j         d         V  |dk    rdV  (dS )z
        Returns the ``test`` nodes found in ``except_clause`` nodes.
        Returns ``[None]`` for except clauses without an exception given.
        r   r'   exceptNr*   r)   r-   r.   s     r0   get_except_clause_testszTryStmt.get_except_clause_tests  s[      
 M 	 	DyO++mA&&&&&!!


		 	r2   N)r3   r4   r5   r)   r6   rj  r    r2   r0   re  re    s-        DI	 	 	 	 	r2   re  c                   $    e Zd ZdZdZddZd ZdS )WithStmtr   r    Fc                     g }| j         ddd         D ]+}|j        dk    r|t          |j         d         |          z  },|S )z}
        Returns the a list of `Name` that the with statement defines. The
        defined names are set after `as`.
        r'   rB  r   	with_item)r*   r)   rb  )r-   rz   r   rn  s       r0   r   zWithStmt.get_defined_names  sV    
 qAv. 	P 	PI~,,	(:1(=OOOr2   c                 h    |                     d          }|t          d          |j        d         S )Nrn  z2The name is not actually part of a with statement.r   )r
   
ValueErrorr*   )r-   r:   r.   s      r0   get_test_node_from_namez WithStmt.get_test_node_from_name  s6    ##K00<QRRR}Qr2   Nr   )r3   r4   r5   r)   r6   r   rq  r    r2   r0   rl  rl    sA        DI
 
 
 
         r2   rl  c                   $    e Zd ZdZd Zd Zd ZdS )Importr    c                     	 |                                  |         }n# t          $ r Y nw xY w|                                 D ](}||v r"|d|                    |          dz            c S )t	          d          )zo
        The path is the list of names that leads to the searched name.

        :return list of Name:
        Nr'   z+Name should be defined in the import itself)_aliasesKeyErrorr   r+   rp  )r-   r:   r   s      r0   get_path_for_namezImport.get_path_for_name  s    	==??4(DD 	 	 	D	 NN$$ 	3 	3Dt||1TZZ--112222 FGGGs    
**c                     dS )NFr    rG   s    r0   	is_nestedzImport.is_nested/  s    ur2   c                 $    | j         d         dk    S )Nr   r  r   rG   s    r0   is_star_importzImport.is_star_import2  s    }R C''r2   N)r3   r4   r5   r6   rw  ry  r{  r    r2   r0   rs  rs    sI        IH H H"  ( ( ( ( (r2   rs  c                   L    e Zd ZdZdZddZd Zd Zed             Z	d Z
d	 Zd
S )
ImportFromr   r    Fc                 >    d |                                  D             S )z
        Returns the a list of `Name` that the import defines. The
        defined names are set after `import` or in case an alias - `as` - is
        present that name is returned.
        c                     g | ]	\  }}|p|
S r    r    r   r:   aliass      r0   r   z0ImportFrom.get_defined_names.<locals>.<listcomp>@  s     HHH+$HHHr2   )_as_name_tuplesr|   s     r0   r   zImportFrom.get_defined_names:  s%     IH1E1E1G1GHHHHr2   c                 X    t          d |                                 D                       S )z-Mapping from alias to its corresponding name.c              3   (   K   | ]\  }}|||fV  d S rE   r    r  s      r0   r  z&ImportFrom._aliases.<locals>.<genexpr>D  s;       * *kdE( DM((((* *r2   )dictr  rG   s    r0   ru  zImportFrom._aliasesB  s;     * *T5I5I5K5K * * * * * 	*r2   c                 ~    | j         dd          D ]}|dvr n	|j        dk    r|j         d d d         S |dk    rg S |gS )Nr'   .z...dotted_namer   importrh  )r-   ns     r0   get_from_nameszImportFrom.get_from_namesG  se    qrr" 	 	A$$ %6]"":ccc?"(]]I3Jr2   c                 f    d}| j         dd         D ]}|dv r|t          |j                  z  } |S )&The level parameter of ``__import__``.r   r'   Nr  r*   rR   rZ   )r-   r   r  s      r0   r   zImportFrom.levelR  sJ     qrr" 	 	AL  QW%r2   c              #      K   | j         d         }|dk    r| j         d         }n|dk    rd S |j        dk    r|j         d d d         }n|g}|D ]&}|j        dk    r|d fV  |j         d d d         V  'd S )Nr   r   rB  r  import_as_namesr   r:   rh  )r-   lastas_namesas_names       r0   r  zImportFrom._as_name_tuples]  s      }R 3;;=$DDS[[F9)))}SSqS)HHvH 	, 	,G|v%%tm####&sss+++++		, 	,r2   c                     |                                  | j        d         dk    rgS fd|                                 D             S )z
        The import paths defined in an import statement. Typically an array
        like this: ``[<Name: datetime>, <Name: date>]``.

        :return list of list of Name:
        r   r  c                 "    g | ]\  }}|gz   S r    r    )r   r:   r  dotteds      r0   r   z(ImportFrom.get_paths.<locals>.<listcomp>y  s#    JJJKD%$JJJr2   )r  r*   r  )r-   r  s    @r0   r   zImportFrom.get_pathsn  sU     $$&&=##8OJJJJ43G3G3I3IJJJJr2   Nr   )r3   r4   r5   r)   r6   r   ru  r  r[   r   r  r   r    r2   r0   r}  r}  6  s        DII I I I* * *
	 	 	   X, , ,"K K K K Kr2   r}  c                   P    e Zd ZdZdZdZddZed             Zd Z	d Z
d	 Zd
 ZdS )
ImportNamezBFor ``import_name`` nodes. Covers normal imports without ``from``.r   r    Fc                 >    d |                                  D             S )z
        Returns the a list of `Name` that the import defines. The defined names
        is always the first name after `import` or in case an alias - `as` - is
        present that name is returned.
        c                 (    g | ]\  }}|p|d          S )r   r    r   r   r  s      r0   r   z0ImportName.get_defined_names.<locals>.<listcomp>  s%    LLL[T5 aLLLr2   _dotted_as_namesr|   s     r0   r   zImportName.get_defined_names  s%     MLD4I4I4K4KLLLLr2   c                     dS )r  r   r    rG   s    r0   r   zImportName.level  s	     qr2   c                 >    d |                                  D             S )Nc                     g | ]\  }}|S r    r    r  s      r0   r   z(ImportName.get_paths.<locals>.<listcomp>  s    @@@u@@@r2   r  rG   s    r0   r   zImportName.get_paths  s"    @@(=(=(?(?@@@@r2   c              #   
  K   | j         d         }|j        dk    r|j         ddd         }n|g}|D ]Q}|j        dk    r|j         d         }|j         d         }nd}|j        dk    r|g|fV  =|j         ddd         |fV  RdS )z9Generator of (list(path), alias) where alias may be None.r'   dotted_as_namesNr   dotted_as_namer   r:   rh  )r-   r  r  r  r  s        r0   r  zImportName._dotted_as_names  s      -*#444&/!4HH'(H 
	3 
	3G|///(+!*1-|v%%i&&&&& &sss+U22222
	3 
	3r2   c                 X    t          d |                                 D                       S )z
        This checks for the special case of nested imports, without aliases and
        from statement::

            import foo.bar
        c                 B    g | ]\  }}|t          |          dk    dS r"  )rR   r  s      r0   r   z(ImportName.is_nested.<locals>.<listcomp>  s6     8 8 8;4}TQ )6r2   )boolr  rG   s    r0   ry  zImportName.is_nested  s=      8 8$*?*?*A*A 8 8 8 9 9 	9r2   c                 X    t          d |                                 D                       S )z=
        :return list of Name: Returns all the alias
        c              3   4   K   | ]\  }}|||d         fV  d S )Nr   r    r  s      r0   r  z&ImportName._aliases.<locals>.<genexpr>  s@       * *+$( DH%((((* *r2   )r  r  rG   s    r0   ru  zImportName._aliases  s=      * *9N9N9P9P * * * * * 	*r2   Nr   )r3   r4   r5   rA   r)   r6   r   r[   r   r   r  ry  ru  r    r2   r0   r  r  |  s        LLDIM M M M   XA A A3 3 3(9 9 9* * * * *r2   r  c                   J    e Zd ZdZdZed             Zed             ZddZdS )	KeywordStatementz
    For the following statements: `assert`, `del`, `global`, `nonlocal`,
    `raise`, `return`, `yield`.

    `pass`, `continue` and `break` are not in there, because they are just
    simple keywords and the parser reduces it to a keyword.
    r    c                     d| j         z  S )z
        Keyword statements start with the keyword and end with `_stmt`. You can
        crosscheck this with the Python grammar.
        z%s_stmt)r   rG   s    r0   r)   zKeywordStatement.type  s     4<''r2   c                 &    | j         d         j        S Nr   )r*   rZ   rG   s    r0   r   zKeywordStatement.keyword  s    }Q%%r2   Fc                 ~    | j         }|dk    rt          | j        d         |          S |dv r| j        dd d         S g S )Ndelr'   )globalnonlocalr   )r   rb  r*   )r-   rz   r   s      r0   r   z"KeywordStatement.get_defined_names  sO    ,e!$-"2ODDD,,,=A&&	r2   Nr   )	r3   r4   r5   rA   r6   r[   r)   r   r   r    r2   r0   r  r    sm          I( ( X( & & X&     r2   r  c                   (    e Zd ZdZed             ZdS )
AssertStmtr    c                     | j         d         S r"  r   rG   s    r0   	assertionzAssertStmt.assertion  r#  r2   N)r3   r4   r5   r6   r[   r  r    r2   r0   r  r    s2        I    X     r2   r  c                       e Zd ZdZd ZdS )
GlobalStmtr    c                 "    | j         dd d         S )Nr'   r   r   rG   s    r0   get_global_nameszGlobalStmt.get_global_names  s    }QTT""r2   N)r3   r4   r5   r6   r  r    r2   r0   r  r    s(        I# # # # #r2   r  c                       e Zd ZdZdS )
ReturnStmtr    Nr_   r    r2   r0   r  r    r`   r2   r  c                       e Zd ZdZdZdS )	YieldExprr(  r    Nr   r    r2   r0   r  r    r[  r2   r  c                    g }| j         dv r(| j        ddd         D ]}|t          ||          z  }n| j         dv r|t          | j        d         |          z  }n| j         dv r| j        d         dk    r| j        d	         }|j        d
         dk    r!|                    |j        d                    n|j        d
         dk    rd|rb| j        ddd	         D ]Q}|j         dk    r"|                    |j        d                     n#|j         dk    r|                    |            nRn|                    |            |S )zk
    A helper function to find the defined names in statements, for loops and
    list comprehensions.
    )testlist_star_exprtestlist_compexprlisttestlistNr   )atom	star_exprr'   )power	atom_exprrB  **r   r   r  [trailerr:   )r)   r*   rb  r   )currentrz   r   r   r  r.   s         r0   rb  rb    s|   
 E|VVV%ccc* 	< 	<E^E?;;;EE	<	.	.	. 0 3_EEE	/	/	/B4''&r*G"c))W-a01111!!$+++#,RVV4  DyI--T]1%5666yF**T*** + 	WLr2   c                   *    e Zd ZdZdZddZd Zd ZdS )	ExprStmtr   r    Fc                      g } j         d         j        dk    rt           j         d                   } fdt          dt	           j                   dz
  d          D             |z   S )zG
        Returns a list of `Name` defined before the `=` sign.
        r'   	annassignr   c                 ~    g | ]9}d j         |dz            j        v t          j         |                   D ]}|:S )=r'   )r*   rZ   rb  )r   rO  r:   rz   r-   s      r0   r   z.ExprStmt.get_defined_names.<locals>.<listcomp>  s^     
 
 
dmAE*000&t}Q'7II 10 0000r2   r   )r*   r)   rb  rangerR   )r-   rz   r   s   `` r0   r   zExprStmt.get_defined_names  s     = K//"4=#3_EEE
 
 
 
 
1c$-0014a88
 
 

  	r2   c                     | j         d         }|j        dk    r3t          |j                   dk    r|j         d         }n|j         d         }|S )z*Returns the right-hand-side of the equals.r   r  r=  r   r'   r*   r)   rR   ri  s     r0   get_rhszExprStmt.get_rhs  sO    }R 9##4=!!Q&&}Q'}Q'r2   c              #      K   | j         d         }|j        dk    r't          |j                   dk    rdS |j         d         }|V  | j         ddd         E d{V  dS )zZ
        Returns a generator of `+=`, `=`, etc. or None if there is no operation.
        r'   r  r   Nr   r  r-   r
  s     r0   yield_operatorszExprStmt.yield_operators'  s{       a :$$5>""a''N1%E=A&&&&&&&&&&r2   Nr   )r3   r4   r5   r)   r6   r   r  r  r    r2   r0   r  r    sP        DI     ' ' ' ' 'r2   r  c                       e Zd ZdZddZdS )	NamedExprr   Fc                 8    t          | j        d         |          S r  ra  r|   s     r0   r   zNamedExpr.get_defined_names9  rc  r2   Nr   )r3   r4   r5   r)   r   r    r2   r0   r  r  6  s3        DA A A A A Ar2   r  c                        e Zd ZdZdZd fd	Zed             Zed             Zed             Z	d Z
ed	             ZddZed             Zd Zd fd	Zd Z xZS )r  z
    It's a helper class that makes business logic with params much easier. The
    Python grammar defines no ``param`` node. It defines it in a different way
    that is not really suited to working with parameters.
    r   Nc                 X    t                                          |           || _        d S rE   )r   r   r,   )r-   r*   r,   r   s      r0   r   zParam.__init__E  s&    """r2   c                 P    | j         d         }|dv rt          |j                  S dS )zc
        Is `0` in case of `foo`, `1` in case of `*foo` or `2` in case of
        `**foo`.
        r   r  r  r  r  s     r0   
star_countzParam.star_countI  s0     a Ku{###qr2   c                     | j         d         dk    }	 | j         dt          |          z
           dk    r| j         dt          |          z
           S dS # t          $ r Y dS w xY w)z{
        The default is the test node that appears after the `=`. Is `None` in
        case no default is present.
        r   rx   rB  r  N)r*   r\   r  )r-   	has_commas     r0   defaultzParam.defaultT  sy     M"%,		}R#i..01S88}R#i..%899 98 	 	 	44	s   =A 
A! A!c                     |                                  }|j        dk    r<|j        d         dk    sJ t          |j                  dk    sJ |j        d         }|S dS )zz
        The default is the test node that appears after `:`. Is `None` in case
        no annotation is present.
        r  r'   r&   r   r   N)_tfpdefr)   r*   rR   )r-   r  r>  s      r0   r>  zParam.annotationa  sh     ;(""?1%,,,,v''1,,,,+J4r2   c                 T    t          | j        d         dv           }| j        |         S )z1
        tfpdef: see e.g. grammar36.txt.
        r   r  )r\   r*   )r-   offsets     r0   r  zParam._tfpdefp  s*     T]1%455}V$$r2   c                     |                                  j        dk    r|                                  j        d         S |                                  S )z/
        The `Name` leaf of the param.
        r  r   )r  r)   r*   rG   s    r0   r:   z
Param.namew  s>    
 <<>>(**<<>>*1--<<>>!r2   Fc                     | j         gS rE   )r:   r|   s     r0   r   zParam.get_defined_names  s    	{r2   c                 :   | j         j                            |           }	 | j         j                            d          }||k    r|dz  }n# t          $ r Y nw xY w	 | j         j                            d          }||k    r|dz  }n# t          $ r Y nw xY w|dz
  S )zB
        Property for the positional index of a paramter.
        r  r   r  r'   )r,   r*   r+   rp  )r-   r+   keyword_only_indexs      r0   position_indexzParam.position_index  s    
 $**400	!%!5!;!;C!@!@)))
 	 	 	D		!%!5!;!;C!@!@)))
 	 	 	D	qys#   *A 
AA*B 
BBc                 .    |                      dd          S )z=
        Returns the function/lambda of a parameter.
        r$   r&  )r
   rG   s    r0   get_parent_functionzParam.get_parent_function  s     ##Iy999r2   Tc                     |r!t                                          |          S | j        }|d         dk    r
|dd         }|                     ||          S )z
        Like all the other get_code functions, but includes the param
        `include_comma`.

        :param include_comma bool: If enabled includes the comma in the string output.
        r   rx   N)include_prefix)r   get_coder*   _get_code_for_children)r-   r  include_commar*   r   s       r0   r  zParam.get_code  sk      	477##N333=B<3}H**) + 
 
 	
r2   c                     | j         dnd| j                                         z  }dt          |           j        dt	          |                                           |z   dS )Nr   z=%srk   rs   rl   )r  r  r)   r3   r   r  )r-   r  s     r0   rn   zParam.__repr__  s\    ,""%$,:O:O:Q:Q2Q!$ZZ000#dllnn2E2E2O2O2OPPr2   rE   r   )TT)r3   r4   r5   rA   r)   r   r[   r  r  r>  r  r:   r   r  r  r  rn   r   r   s   @r0   r  r  =  s;        
 D        X 
 
 X
   X% % % " " X"      X*: : :
 
 
 
 
 
$Q Q Q Q Q Q Qr2   r  c                       e Zd ZdZdZddZdS )SyncCompForr   r    Fc                 8    t          | j        d         |          S )zN
        Returns the a list of `Name` that the comprehension defines.
        r'   ra  r|   s     r0   r   zSyncCompFor.get_defined_names  s    
 dmA.@@@r2   Nr   )r3   r4   r5   r)   r6   r   r    r2   r0   r  r    s8        DIA A A A A Ar2   r  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	r   zO
    This class exists for the sole purpose of creating an immutable dict.
    c                     || _         d S rE   _dict)r-   r   s     r0   r   zUsedNamesMapping.__init__  s    


r2   c                     | j         |         S rE   r  )r-   keys     r0   __getitem__zUsedNamesMapping.__getitem__  s    z#r2   c                 *    t          | j                  S rE   )rR   r  rG   s    r0   __len__zUsedNamesMapping.__len__  s    4:r2   c                 *    t          | j                  S rE   )iterr  rG   s    r0   __iter__zUsedNamesMapping.__iter__  r   r2   c                      t          |           S rE   )idrG   s    r0   r   zUsedNamesMapping.__hash__  s    $xxr2   c                 
    | |u S rE   r    r   s     r0   r   zUsedNamesMapping.__eq__  s    u}r2   N)
r3   r4   r5   rA   r   r  r   r  r   r   r    r2   r0   r   r     sx                          r2   r   )JrA   r   collections.abcr   ImportErrorcollectionstypingr   
parso.treer   r   r   r   r	   r
   parso.python.prefixr   parso.utilsr   set_FLOW_CONTAINERSr0  r   r   r   r   r8   rC   rV   r^   rb   rd   rf   rh   rp   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r@  rI  rK  rZ  r]  re  rl  rs  r}  r  r  r  r  r  r  rb  r  r  r  r  CompForr   r    r2   r0   <module>r     s	  * *X 
			$''''''' $ $ $########$       R R R R R R R R R R R R R R R R , , , , , , # # # # # #3 < < < = = #w677:JJ 3:::          3}-..       8       ,% % % % %d % % %08 8 8 8 8: 8 8 8    [(       d       k9       i   
 
 
 
 
$ 
 
 
D D D D Dj D D D1 1 1 1 1 1 1 1h    j       W   
5 5 5 5 5W 5 5 5"    J       :                         "    #%;   
    "$:   
4G 4G 4G 4G 4GNN 4G 4G 4Gn3  3  3  3  3 U 3  3  3 l       
    %   6( ( ( ( (K ( ( (0* * *Zj j j j j{ j j jZ*E *E *E *E *EX *E *E *EZ    >   * * * * *T * * *Z       
A A A A Ad A A A    d             t      .( ( ( ( (^ ( ( (6CK CK CK CK CK CK CK CKL8* 8* 8* 8* 8* 8* 8* 8*v    ~   >         !      # # # # #! # # #    !          
  :(' (' (' (' ('~~ (' (' ('VA A A A A A A AwQ wQ wQ wQ wQN wQ wQ wQt	A 	A 	A 	A 	A. 	A 	A 	A     w     s    