bBFjdZddlZddlmZddlmZmZddlmZm Z m Z m Z m Z m Z ddlmZddlmZegdZed d gezZegd ezZegd Zed dgZGddZGddZGddee ZGddeZGddee ZGddeeZGddee ZGdde eZGdd eZ Gd!d"eZ!Gd#d$eZ"Gd%d&eZ#Gd'd(e#Z$Gd)d*e#Z%Gd+d,eZ&Gd-d.eZ'Gd/d0eZ(Gd1d2Z)Gd3d4ee)Z*Gd5d6ee)Z+Gd7d8eeZ,Gd9d:e,Z-Gd;de,Z/Gd?d@e/Z0dAZ1GdBdCe/Z2GdDdEe2Z3GdFdGeZ4GdHdIe4Z5GdJdKe4Z6GdLdMe4Z7GdNdOe4Z8GdPdQe4Z9GdRdSeZ:GdTdUe:Z;GdVdWe:Z<GdXdYeZ=GdZd[e=Z>Gd\d]e=Z?Gd^d_e=Z@Gd`daeZAdbZBGdcddeeZCGdedfeZDGdgdheZEGdidjeZFeFZGGdkdleZHdS)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 `_. 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 Any subclasses of :class:`Scope`, including :class:`Module` has an attribute :attr:`iter_imports `: >>> list(module.iter_imports()) [] 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)TupleAny)NodeBaseNodeLeaf ErrorNode ErrorLeafsearch_ancestor) split_prefix) split_lines)if_stmt while_stmtfor_stmttry_stmt with_stmt async_stmtsuiter simple_stmt)rr decorated async_funcdef) expr_stmt sync_comp_forrr import_name import_fromparamdel_stmtnamedexpr_testrrc8eZdZUdZeed<ded<eed<dZdS)DocstringMixintype list[Any]childrenparentc|jdkr|jd}n|jdvrA|j|jddz}|jdkr |jd}n7|j}|jj}||}|sdS||dz }|jdkr |jd}|jd kr|SdS) zN Returns the string leaf of a docstring. e.g. ``r'''foo'''``. file_inputrfuncdefclassdef:rNrstring)r"r$indexr%)selfnodercr.s ?C:\PYTHON\_runtimes\venv\Lib\site-packages\parso/python/tree.py get_doc_nodezDocstringMixin.get_doc_nodeJs 9 $ $=#DD Y1 1 1=!4!4S!9!9A!=>DyG##}Q'+K"+AGGK((E tUQY">"@"@AAAr4c|}|(|jdkr|jdvr|}|0t|j}|jt |z dzdfS|jS)z[ Basically calls :py:meth:`parso.tree.NodeOrLeaf.get_start_pos_of_prefix`. N error_leaf)INDENTDEDENT ERROR_DEDENTr,r)get_previous_leafr" token_typer prefixlinelenrA)r/ previous_leafliness r2rJz"PythonLeaf.get_start_pos_of_prefixs ..00  $);|)K)K!,0TTT);;==M   ,,E9s5zz)A-q0 0$$r4N)r5r6r7r8rLrJr!r4r2rGrGzs:IBBB%%%%%r4rGcBeZdZdZdZedeeeffdZdS)_LeafWithoutNewlinesz. Simply here to optimize performance. r!returncH|j|jt|jzfSrI)rUcolumnrVvaluerKs r2rAz_LeafWithoutNewlines.end_possy$+DJ777r4N) r5r6r7rEr8propertyrintrAr!r4r2rZrZsRI 8sCx888X888r4rZceZdZdZdS)PythonBaseNoder!Nr5r6r7r8r!r4r2rbrbIIIr4rbceZdZdZdS) PythonNoder!Nrcr!r4r2rfrfrdr4rfceZdZdZdS)PythonErrorNoder!Nrcr!r4r2rhrhrdr4rhceZdZdZdS)PythonErrorLeafr!Nrcr!r4r2rjrjrdr4rjceZdZdZdZdZdS) EndMarkerr! endmarkercldt|jdt|jd|jdS)N)r"r5reprrTrArKs r2__repr__zEndMarker.__repr__s: JJ   dk!2!2!2!2DLLL  r4N)r5r6r7r8r"rrr!r4r2rlrls-I D     r4rlc eZdZdZdZdZdZdS)Newlinez&Contains NEWLINE and ENDMARKER tokens.r!newlinec\dt|jdt|jdS)Nro: rp)r"r5rqr^rKs r2rrzNewline.__repr__s.!$ZZ000$tz2B2B2B2BCCr4N)r5r6r7rEr8r"rrr!r4r2rtrts800I DDDDDDr4rtc0eZdZdZdZdZdZd dZd dZdS) Nameza A string. Sometimes it is important to know if the string belongs to a name or not. r>r!c bdt|jd|jd|jd|jd S)Nrorw@,rp)r"r5r^rUr]rKs r2rrz Name.__repr__s9#'::#6#6#6 #'999dkkk; ;r4Fc2||duS)z< Returns True if the name is being defined. )include_setitemN)get_definitionr/r~s r2 is_definitionzName.is_definitions ""?"CC4OOr4c<|j}|j}|dvr||jkr|SdS|dkr!|dkr|jSdS|Q|jdkrdS|jtvr-|||vr|S|r|jt vr|SdS|j}|QdS)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_clauseasr)r%r"r>get_previous_sibling_GET_DEFINITION_TYPESget_defined_names_IMPORTS)r/import_name_alwaysr~r0type_s r2rzName.get_definitions{  + + +ty   4 O # #((**d22{"4yG##ty111411/BBBBK% $)x*?*?Kt;Dtr4NF)FF) r5r6r7rEr"r8rrrrr!r4r2ryryse DI;;;PPPP r4ryceZdZdZdS)Literalr!Nrcr!r4r2rrrdr4rceZdZdZdZdS)Numbernumberr!Nr5r6r7r"r8r!r4r2rrs DIIIr4rc2eZdZdZdZedZdZdS)Stringr-r!c\tjd|jdS)Nz \w*(?=[\'"])r)rematchr^grouprKs r2 string_prefixzString.string_prefixs$x44::1===r4ctjd|jtj}|ddt |d S)Nz('{3}|"{3}|'|")(.*)$)flagsr,)rsearchr^DOTALLrrV)r/rs r2 _get_payloadzString._get_payloadsW ' J)    {{1~~3EKKNN 3 33344r4N)r5r6r7r"r8r_rrr!r4r2rrsF DI >>X>55555r4rceZdZdZdZdZdS) FStringStringx f-strings contain f-string expressions and normal python strings. These are the string parts of f-strings. fstring_stringr!Nr5r6r7rEr"r8r!r4r2rrs$ DIIIr4rceZdZdZdZdZdS) FStringStartr fstring_startr!Nrr!r4r2rrs$ DIIIr4rceZdZdZdZdZdS) FStringEndr fstring_endr!Nrr!r4r2rr!s$ DIIIr4rc*eZdZUdZeed<dZdZdS)_StringComparisonMixinr!r^cJt|tr |j|kS||uS)ze Make comparisons with strings easy. Improves the readability of the parser. )r?r9r^r/others r2__eq__z_StringComparisonMixin.__eq__.s- eS ! ! ':& &u}r4c*t|jSrI)hashr^rKs r2__hash__z_StringComparisonMixin.__hash__8DJr4N)r5r6r7r8rr:rrr!r4r2rr*sBI JJJ     r4rceZdZdZdZdS)Operatoroperatorr!Nrr!r4r2rr<s DIIIr4rceZdZdZdZdS)Keywordkeywordr!Nrr!r4r2rrAs DIIIr4rcJeZdZdZdZfdZdZdZdZdZ dZ d Z xZ 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!cJt|dSrIsuper__init__r/r$ __class__s r2rzScope.__init__N! """""r4c,|dS)z9 Returns a generator of `funcdef` nodes. r)_search_in_scoperKs r2 iter_funcdefszScope.iter_funcdefsQs$$Y///r4c,|dS)z: Returns a generator of `classdef` nodes. r*rrKs r2iter_classdefszScope.iter_classdefsWs$$Z000r4c.|ddS)zO Returns a generator of `import_name` and `import_from` nodes. rrrrKs r2 iter_importszScope.iter_imports]s$$]MBBBr4c2fd|jS)Nc3xK|D]3}|jvr|V|jtvr|jEd{V4dSrI)r"_FUNC_CONTAINERSr$)r$elementnamesscans r2rz$Scope._search_in_scope..scandsj# 6 6<5((!MMM<#333#tG$4555555555  6 6r4r$)r/rrs `@r2rzScope._search_in_scopecs6 6 6 6 6 6 6tDM"""r4c|jdS)zD Returns the part that is executed by the function. rrKs r2 get_suitezScope.get_suitems}R  r4c  |jj}n#t$rd}YnwxYwdt|jd|d|jdd|jdd S)Nrorwr{r-rp)r>r^AttributeErrorr"r5r@rA)r/r>s r2rrzScope.__repr__ssy 9?DD   DDD $(::#6#6#6#'>!#4#4#4dl1oooG Gs  ) r5r6r7rEr8rrrrrrrr __classcell__rs@r2rrFs I#####000 111 CCC ###!!! GGGGGGGr4rc6eZdZdZdZdZfdZdZdZxZ 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'cXt|d|_dSrI)rrrrs r2rzModule.__init__s) """r4c#K|D]d}|jdkrW|jdkrL|D]7}d|D}t |dkr|ddkr |dV8edS)zU :return: A list of future import names. :rtype: list of str rrcg|] }|j Sr!)r^).0r>s r2 z4Module._iter_future_import_names..s999DTZ999r4r __future__r,N)rr"level get_pathsrV)r/imppathrs r2_iter_future_import_namesz Module._iter_future_import_namess$$&& ' 'Cx=((SY!^^MMOO''D99D999E5zzQ58|+C+C#Ah  ' 'r4cp|j'ifd|t|_|jS)z Returns all the :class:`Name` leafs that exist in this module. This includes both definitions and references of names. Nc |j}|D] }|dS#t$rB|jdkr3|jg}||YdSYdSwxYw)Nr>)r$rr" setdefaultr^append)r0r$childarrdctrecurses r2rz&Module.get_used_names..recurses'#}H "*'''' &)))yF**!nnTZ<< 4((((((+**)sAA('A()rUsedNamesMapping)r/rrs @@r2get_used_nameszModule.get_used_namessZ   #C ' ' ' ' ' ' GDMMM/44D r4) r5r6r7rEr8r"rrrrrs@r2rr}sl !I D     '''        r4rceZdZdZdZdS) Decorator decoratorr!Nrr!r4r2rrs DIIIr4rc.eZdZdZedZdZdS) ClassOrFuncr!c|jdS)zR Returns the `Name` leaf that defines the function or class name. r,rrKs r2r>zClassOrFunc.names }Qr4c|j}|jdkr|j}|jdkr7|jdjdkr|jdjS|jddSgS)z4 :rtype: list of :class:`Decorator` rrr decoratorsNr,)r%r"r$)r/rs r2get_decoratorszClassOrFunc.get_decoratorsskK >_ , ,!(I >[ ( (!!$)\99 )!,55 )"1"--Ir4N)r5r6r7r8r_r>rr!r4r2rrsAI   X r4rc0eZdZdZdZdZfdZdZxZS)Classz> Used to store the parsed contents of a python class. r*r!cJt|dSrIrrs r2rzClass.__init__rr4ct|jD](\}}|dkr|j|dz}|dkrdS|cS)dS)z Returns the `arglist` node that defines the super classes. It returns None if there are no arguments. (r,)N enumerater$)r/ir next_childs r2get_super_arglistzClass.get_super_arglistsd "$-00 " "HAu||!]1q51 $$44!!!!  tr4) r5r6r7rEr"r8rrrrs@r2rrs] DI#####       r4rc |d}n#t$rgcYSwxYw|jdvrt|g|gS|dkr|gS|jdkr|g}n|j}g}d}t |dgzdD]\}}||dkrz|||}|rn|ddkrt |dks|ddks |ddkr|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,r|/) IndexErrorr"Paramr$rrVr%r) r% argslist_listfirstr$ new_childrenstartendrparam_childrenps r2_create_paramsrska    z&&&ugv&&'' #w : ! !wHH~H #Hv$5q99 JC} !)%)!4!  %a(C//!$^!4!4!9!9$21$5$<$<-a0C77!/..A'-AHH$6 $++E.&,I,IJJJEs  ceZdZdZdZdZfdZdZdZdZ e dZ d Z d Z d Zd Ze d ZxZS)Functionan Used to store the parsed contents of a python function. Children:: 0. 1. 2. parameter list (including open-paren and close-paren s) 3. or 5. 4. or 6. Node() representing function body 3. -> (if annotation is also present) 4. annotation (if present) r)r!ct||}|jdd}t d|Dst |||jdd<dSdS)Nr,rc3@K|]}t|tVdSrIr?r rrs r2 z$Function.__init__..-,MM:eU++MMMMMMr4)rr_find_parametersr$anyr)r/r$ parametersparameters_childrenrs r2rzFunction.__init__)s """**,, (1!B$7MM9LMMMMM (6/))J " % % %  r4cR|jD]}|jdkr|cStd)Nr z(A function should always have parameters)r$r" Exception)r/rs r2rzFunction._find_parameters2s=]  Ez\)) *BCCCr4c4|jSrI)rr$rKs r2_get_param_nodeszFunction._get_param_nodes8s$$&&//r4c>d|DS)z. Returns a list of `Param()`. c(g|]}|jdk |S)r)r")rrs r2rz'Function.get_params..?s$HHHaaf6G6G6G6G6Gr4)r%rKs r2 get_paramszFunction.get_params;s%IH40022HHHHr4c|jdSNr,rrKs r2r>z Function.nameA}Qr4c.fd|jS)z6 Returns a generator of `yield_expr`. c3K|D]^}|jdvr |j}|Ed{V&#t$r,|jdkr|jjdkr |jVn|VY[wxYwdS)N)r*r)lambdefyield yield_expr)r"r$rr^r%)r$rnested_childrenrs r2rz'Function.iter_yield_exprs..scanIs# 5 5<#EEE 5&-&6O $tO4444444444&***}//">.,>>").0000")MMM * 5 5s,3A"!A"rr/rs @r2iter_yield_exprszFunction.iter_yield_exprsEs0 5 5 5 5 5 tDM"""r4c.fd|jS)z7 Returns a generator of `return_stmt`. c3K|D]K}|jdks|jdkr|jdkr|V|jtvr|jEd{VLdS)N return_stmtrr[r"r^_RETURN_STMT_CONTAINERSr$r$rrs r2rz(Function.iter_return_stmts..scan_s# 6 6<=00"<944(9R9R!MMM<#:::#tG$4555555555  6 6r4rr2s @r2iter_return_stmtszFunction.iter_return_stmts[0 6 6 6 6 6tDM"""r4c.fd|jS)zi Returns a generator of `raise_stmt`. Includes raise statements inside try-except blocks c3K|D]K}|jdks|jdkr|jdkr|V|jtvr|jEd{VLdS)N raise_stmtrraiser7r9s r2rz'Function.iter_raise_stmts..scanms# 6 6<<//"<944'9Q9Q!MMM<#:::#tG$4555555555  6 6r4rr2s @r2iter_raise_stmtszFunction.iter_raise_stmtsir;r4cJt|dduS)zK :return bool: Checks if a function is a generator or not. N)nextr3rKs r2 is_generatorzFunction.is_generatorws%D))++T22$>>r4cjt|jD]\}}|dkr|j|dzcSdS)zW Returns the test node after `->` or `None` if there is no annotation. z->r,Nr)r/rrs r2 annotationzFunction.annotation}sK "$-00 , ,HAu}}}QU++++tr4)r5r6r7rEr"r8rrr%r(r_r>r3r:r@rCrErrs@r2rrs   DIDDD 000III   X ###, # # # # # #??? Xr4rcbeZdZdZdZdZfdZedZdZ edZ dZ xZ S) Lambdaz Lambdas are basically trimmed functions, so give it the same interface. Children:: 0. *. for each argument x -2. -1. Node() representing body r.r!ctt|||jdd}t d|Dst |||jdd<dSdS)Nr,c3@K|]}t|tVdSrIrrs r2rz"Lambda.__init__..rr4)rrrr$rr)r/r$r!rs r2rzLambda.__init__s h&&x000"mAbD1MM9LMMMMM L"07J"K"KDM!B$    L Lr4c td)zN Raises an AttributeError. Lambdas don't have a defined name. zlambda is not named.)rrKs r2r>z Lambda.names 3444r4c |jddS)Nr,rIrrKs r2r%zLambda._get_param_nodess}QrT""r4cdS)zA Returns `None`, lambdas don't have annotations. Nr!rKs r2rEzLambda.annotations tr4c2d|jjd|jdS)Nror{rp)rr5r@rKs r2rrzLambda.__repr__s  N333T^^^DDr4) r5r6r7rEr"r8rr_r>r%rErrrrs@r2rGrGs   DILLLLL55X5 ###X EEEEEEEr4rGceZdZdZdS)Flowr!Nrcr!r4r2rPrPrdr4rPc(eZdZdZdZdZdZdZdS)IfStmtrr!c#jKt|jD]\}}|dvr|j|dzVdS)z E.g. returns all the `test` nodes that are named as x, below: if x: pass elif x: pass )elififr,Nr)r/rr1s r2get_test_nodeszIfStmt.get_test_nodessRdm,, + +DAqN""mAE**** + +r4c|j}tt|D]}|j|kr||jkrdS|cS dS)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@reversedlistrVrA)r/r0r@ check_nodes r2get_corresponding_test_nodez"IfStmt.get_corresponding_test_nodesv N "4(;(;(=(=#>#>?? & &J#i//z11144&%%% 0 & &r4cL|jD]}|dkr|j|jkrdSdS)z; Checks if a node is defined after `else`. elseTF)r$r@)r/r0r1s r2is_node_after_elsezIfStmt.is_node_after_elses:  AF{{>AK//445r4N)r5r6r7r"r8rVr[r^r!r4r2rRrRsK DI + + +&&&     r4rRceZdZdZdZdS) WhileStmtrr!Nrr!r4r2r`r` DIIIr4r`c$eZdZdZdZdZddZdS)ForStmtrr!c|jdS)zE Returns the input node ``y`` from: ``for x in y:``. rrKs r2 get_testlistzForStmt.get_testlists}Qr4Fc8t|jd|Sr*_defined_namesr$rs r2rzForStmt.get_defined_namesdmA.@@@r4Nr)r5r6r7r"r8rfrr!r4r2rcrcsG DI   AAAAAAr4rcceZdZdZdZdZdS)TryStmtrr!c#hK|jD]'}|jdkr|jdV|dkrdV(dS)z Returns the ``test`` nodes found in ``except_clause`` nodes. Returns ``[None]`` for except clauses without an exception given. rr,exceptNr$r"r/r0s r2get_except_clause_testszTryStmt.get_except_clause_testss[ M  DyO++mA&&&&&!!   r4N)r5r6r7r"r8rqr!r4r2rlrls- DI     r4rlc$eZdZdZdZddZdZdS)WithStmtrr!Fcg}|jdddD]+}|jdkr|t|jd|z },|S)z} Returns the a list of `Name` that the with statement defines. The defined names are set after `as`. r,rIr with_item)r$r"ri)r/r~rrus r2rzWithStmt.get_defined_names sV qAv. P PI~,, (:1(=OOO r4ch|d}|td|jdS)Nruz2The name is not actually part of a with statement.r)r ValueErrorr$)r/r>r0s r2get_test_node_from_namez WithStmt.get_test_node_from_names6##K00 <QRR R}Qr4Nr)r5r6r7r"r8rrxr!r4r2rsrs sA DI         r4rsc@eZdZUdZeed<eed<dZdZdZdZ dS) Importr!r_aliasesc ||}n#t$rYnwxYw|D](}||vr"|d||dzcS)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)r{KeyErrorrr.rw)r/r>rs r2get_path_for_namezImport.get_path_for_name%s  ==??4(DD    D NN$$ 3 3Dt||1TZZ--112222FGGGs  **cdS)NFr!rKs r2 is_nestedzImport.is_nested6sur4c$|jddkS)Nrr rrKs r2is_star_importzImport.is_star_import9s}R C''r4c td)NzUse ImportFrom or ImportName)NotImplementedErrorrKs r2rzImport.get_defined_names<s!"@AAAr4N) r5r6r7r8rr:r~rrrr!r4r2rzrz sqINNNMMMHHH"(((BBBBBr4rzcLeZdZdZdZd dZdZdZedZ dZ d Z d S) ImportFromrr!Fc>d|DS)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. cg|] \}}|p| Sr!r!rr>aliass r2rz0ImportFrom.get_defined_names..Js HHH+$ HHHr4)_as_name_tuplesrs r2rzImportFrom.get_defined_namesDs% IH1E1E1G1GHHHHr4cXtd|DS)z-Mapping from alias to its corresponding name.c3(K|] \}}|||fVdSrIr!rs r2rz&ImportFrom._aliases..Ns;**kdE(DM((((**r4)dictrrKs r2r{zImportFrom._aliasesLs;**T5I5I5K5K***** *r4c~|jddD]}|dvrn |jdkr|jdddS|dkrgS|gS)Nr,.z... dotted_namerimportro)r/ns r2get_from_nameszImportFrom.get_from_namesQseqrr"  A $$% 6] " ":ccc? " (]]I3Jr4cfd}|jddD]}|dvr|t|jz }|S)&The level parameter of ``__import__``.rr,Nrr$rVr^)r/rrs r2rzImportFrom.level\sJqrr"  AL  QW% r4c#K|jd}|dkr|jd}n|dkrdS|jdkr|jddd}n|g}|D]&}|jdkr|dfV|jdddV'dS)NrrrIr import_as_namesrr>ro)r/lastas_namesas_names r2rzImportFrom._as_name_tuplesgs}R  3;;=$DD S[[ F 9) ) )}SSqS)HHvH , ,G|v%%tm####&sss+++++  , ,r4c||jddkrgSfd|DS)z The import paths defined in an import statement. Typically an array like this: ``[, ]``. :return list of list of Name: rr c"g|] \}}|gz Sr!r!)rr>rdotteds r2rz(ImportFrom.get_paths..s#JJJKD%$JJJr4)rr$r)r/rs @r2rzImportFrom.get_pathsxsU$$&& =  # #8OJJJJ43G3G3I3IJJJJr4Nr) r5r6r7r"r8rr{rr_rrrr!r4r2rr@s DIIIII***   X,,," K K K K Kr4rcPeZdZdZdZdZd dZedZdZ dZ d Z d Z d S) ImportNamezBFor ``import_name`` nodes. Covers normal imports without ``from``.rr!Fc>d|DS)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|dS)rr!rrrs r2rz0ImportName.get_defined_names..s%LLL[T5 aLLLr4_dotted_as_namesrs r2rzImportName.get_defined_namess% MLD4I4I4K4KLLLLr4cdS)rrr!rKs r2rzImportName.levels qr4c>d|DS)Ncg|]\}}|Sr!r!rs r2rz(ImportName.get_paths..s@@@u@@@r4rrKs r2rzImportName.get_pathss"@@(=(=(?(?@@@@r4c# K|jd}|jdkr|jddd}n|g}|D]Q}|jdkr|jd}|jd}nd}|jdkr|g|fV=|jddd|fVRdS)z9Generator of (list(path), alias) where alias may be None.r,dotted_as_namesNrdotted_as_namerr>ro)r/rrrrs r2rzImportName._dotted_as_namess-*  #4 4 4&/!4HH'(H 3 3G|///(+!*1-|v%%i&&&&&&sss+U22222 3 3r4cXtd|DS)z This checks for the special case of nested imports, without aliases and from statement:: import foo.bar cBg|]\}}|t|dkdSr*)rVrs r2rz(ImportName.is_nested..s6888;4}TQ)6r4)boolrrKs r2rzImportName.is_nesteds=88$*?*?*A*A88899 9r4cXtd|DS)z= :return list of Name: Returns all the alias c34K|]\}}|||dfVdS)Nrr!rs r2rz&ImportName._aliases..s@**+$(DH%((((**r4)rrrKs r2r{zImportName._aliasess=**9N9N9P9P***** *r4Nr) r5r6r7rEr"r8rr_rrrrr{r!r4r2rrsLL DIMMMMXAAA333(999*****r4rcJeZdZdZdZedZedZddZdS) 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!cd|jzS)z Keyword statements start with the keyword and end with `_stmt`. You can crosscheck this with the Python grammar. z%s_stmt)rrKs r2r"zKeywordStatement.types 4<''r4c&|jdjSNr)r$r^rKs r2rzKeywordStatement.keywords}Q%%r4Fc~|j}|dkrt|jd|S|dvr|jdddSgS)Ndelr,)globalnonlocalr)rrir$)r/r~rs r2rz"KeywordStatement.get_defined_namessO, e  !$-"2ODD D , , ,=A& & r4Nr) r5r6r7rEr8r_r"rrr!r4r2rrsmI ((X(&&X&r4rc(eZdZdZedZdS) AssertStmtr!c|jdSr*rrKs r2 assertionzAssertStmt.assertionr+r4N)r5r6r7r8r_rr!r4r2rrs2I   X   r4rceZdZdZdZdS) GlobalStmtr!c"|jdddS)Nr,rrrKs r2get_global_nameszGlobalStmt.get_global_namess}QTT""r4N)r5r6r7r8rr!r4r2rrs(I#####r4rceZdZdZdS) ReturnStmtr!Nrcr!r4r2rrrdr4rceZdZdZdZdS) YieldExprr0r!Nrr!r4r2rrrar4rcg}|jdvr(|jdddD]}|t||z }n |jdvr|t|jd|z }n|jdvr|jddkr|jd }|jd d kr!||jdn|jd d krd|rb|jddd D]Q}|jd kr"||jdn#|jdkr||nRn|||S)zk A helper function to find the defined names in statements, for loops and list comprehensions. )testlist_star_expr testlist_compexprlisttestlistNr)atom star_exprr,)power atom_exprrI**rrr[trailerr>)r"r$rir)currentr~rrrr0s r2riris| E|VVV%ccc* < r~r/s r2rz.ExprStmt.get_defined_names.. s^   dmAE*000&t}Q'7II10 0000r4r)r$r"rirangerV)r/r~rs`` r2rzExprStmt.get_defined_namess =  K / /"4=#3_EEE     1c$-0014a88     r4c|jd}|jdkr3t|jdkr|jd}n |jd}|S)z*Returns the right-hand-side of the equals.rrrer,r$r"rVrps r2get_rhszExprStmt.get_rhs'sO}R  9 # #4=!!Q&&}Q'}Q' r4c#K|jd}|jdkr't|jdkrdS|jd}|V|jdddEd{VdS)zZ Returns a generator of `+=`, `=`, etc. or None if there is no operation. r,rrNrerr/rs r2yield_operatorszExprStmt.yield_operators1s{ a  : $ $5>""a''N1%E =A&&&&&&&&&&r4Nr)r5r6r7r"r8rrrr!r4r2rrsP DI     ' ' ' ' 'r4rceZdZdZddZdS) NamedExprrFc8t|jd|Srrhrs r2rzNamedExpr.get_defined_namesCrjr4Nr)r5r6r7r"rr!r4r2rr@s3 DAAAAAAr4rceZdZdZdZdfd ZedZedZedZ dZ ed Z dd Z ed Z d Zdfd ZdZxZS)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. rNcXt|||_dSrI)rrr%)r/r$r%rs r2rzParam.__init__Os& """ r4cP|jd}|dvrt|jSdS)zc Is `0` in case of `foo`, `1` in case of `*foo` or `2` in case of `**foo`. rr rrrs r2 star_countzParam.star_countSs0  a  K  u{## #qr4c|jddk} |jdt|z dkr|jdt|z SdS#t$rYdSwxYw)z{ The default is the test node that appears after the `=`. Is `None` in case no default is present. rr|rIrN)r$r`r )r/ has_commas r2defaultz Param.default^sy M"%,  }R#i..01S88}R#i..%89998   44 s=A A! A!c|}|jdkr<|jddksJt|jdksJ|jd}|SdS)zz The default is the test node that appears after `:`. Is `None` in case no annotation is present. r r,r+rerN)_tfpdefr"r$rV)r/r rEs r2rEzParam.annotationksh  ;( " "?1%,,,,v''1,,,,+J 4r4cTt|jddv}|j|S)z1 tfpdef: see e.g. grammar36.txt. rr)r`r$)r/offsets r2rz Param._tfpdefzs*T]1%455}V$$r4c|jdkr|jdS|S)z/ The `Name` leaf of the param. r r)rr"r$rKs r2r>z Param.names> <<>> ( * *<<>>*1- -<<>> !r4Fc|jgSrI)r>rs r2rzParam.get_defined_namess  {r4c:|jj|} |jjd}||kr|dz}n#t$rYnwxYw |jjd}||kr|dz}n#t$rYnwxYw|dz S)zB Property for the positional index of a paramter. r rr r,)r%r$r.rw)r/r.keyword_only_indexs r2position_indexzParam.position_indexs  $**400 !%!5!;!;C!@!@ )))     D  !%!5!;!;C!@!@ )))     D qys#*A AA*B BBc.|ddS)z= Returns the function/lambda of a parameter. r)r.)r rKs r2get_parent_functionzParam.get_parent_functions##Iy999r4Tc|r!t|S|j}|ddkr |dd}|||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. rr|N)include_prefix)rget_coder$_get_code_for_children)r/r include_commar$rs r2rzParam.get_codesk  477##N33 3= B<3  }H** )+   r4c|jdnd|jz}dt|jdt ||zdS)Nrz=%srorwrp)rrr"r5r9r)r/rs r2rrzParam.__repr__s\ ,""%$,:O:O:Q:Q2Q!$ZZ000#dllnn2E2E2O2O2OPPr4rIr)TT)r5r6r7rEr"rr_rrrErr>rrrrrrrrs@r2r r Gs; DX  X   X %%%""X"X*:::       $QQQQQQQr4r ceZdZdZdZddZdS) SyncCompForrr!Fc8t|jd|S)zN Returns the a list of `Name` that the comprehension defines. r,rhrs r2rzSyncCompFor.get_defined_namess dmA.@@@r4Nr)r5r6r7r"r8rr!r4r2rrs8 DIAAAAAAr4rc6eZdZdZdZdZdZdZdZdZ dS) rzO This class exists for the sole purpose of creating an immutable dict. c||_dSrI_dict)r/rs r2rzUsedNamesMapping.__init__s  r4c|j|SrIr)r/keys r2 __getitem__zUsedNamesMapping.__getitem__sz#r4c*t|jSrI)rVrrKs r2__len__zUsedNamesMapping.__len__s4:r4c*t|jSrI)iterrrKs r2__iter__zUsedNamesMapping.__iter__rr4c t|SrI)idrKs r2rzUsedNamesMapping.__hash__s $xxr4c ||uSrIr!rs r2rzUsedNamesMapping.__eq__s u}r4N) r5r6r7rErrr r rrr!r4r2rrsx   r4r)IrErcollections.abcrtypingrr parso.treerrrr r r parso.python.prefixr parso.utilsr set_FLOW_CONTAINERSr8rrrr r<rGrZrbrfrhrjrlrtryrrrrrrrrrrrrrrrrrGrPrRr`rcrlrsrzrrrrrrrrirrr rCompForrr!r4r2rsm **X ######RRRRRRRRRRRRRRRR,,,,,,######3<<<==#w 677:JJ3::: 3 }- . .>.%%%%%d%%%088888:888[(dk9i     $   DDDDDjDDD11111 111hjW 55555W555"J:        $#%; "$: 4G4G4G4G4GNN4G4G4Gn3 3 3 3 3 U3 3 3 l %6K0***Zmmmmm{mmm`*E*E*E*E*EX*E*E*EZ>*****T***Z A A A A Ad A A A     d         t   .BBBBB^BBB@CKCKCKCKCKCKCKCKL8*8*8*8*8*8*8*8*v~>     !   #####!###! :('('('('('~~('('('VAAAAAAAAwQwQwQwQwQNwQwQwQt A A A A A. A A A wr4