K ijdZddlZ ddlmZddlmZddlm Z m Z m Z m Z m Z mZddlmZddlmZegdZed d gezZegd ezZegd Zed dgZGddZGddZGddee ZGddeZGddee ZGddee ZGddee ZGdde eZ Gdd 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-Z0Gd?d@e0Z1dAZ2GdBdCe0Z3GdDdEe3Z4GdFdGeZ5GdHdIe5Z6GdJdKe5Z7GdLdMe5Z8GdNdOe5Z9GdPdQe5Z:GdRdSeZ;GdTdUe;Z<GdVdWe;Z=GdXdYeZ>GdZd[e>Z?Gd\d]e>Z@Gd^d_e>ZAGd`daeZBdbZCGdcddeeZDGdedfeZEGdgdheZFGdidjeZGeGZHGdkdleZIy#e$r ddlmZYqwxYw)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)Tuple)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_testrrceZdZdZdZy)DocstringMixinc|jdk(r|jd}n|jdvrJ|j|jjddz}|jdk(rN|jd}n>|j}|jj}|j|}|sy||dz }|jdk(r|jd}|jd k(r|Sy) zN Returns the string leaf of a docstring. e.g. ``r'''foo'''``. file_inputrfuncdefclassdef:rNrstring)typechildrenindexparent)selfnodercr+s W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/parso/python/tree.py get_doc_nodezDocstringMixin.get_doc_nodeJs 99 $==#D YY1 1==!4!4S!9A!=>DyyG#}}Q'++K""++AGGK(EUQYz PythonMixin.get_name_of_positionisn  "A!T"66V# x(L199(LH)M//9%!M "r2N)r3r4r5__doc__r6r>r r2r0r8r8csI r2r8ceZdZdZdZdZy) PythonLeafr c6t||jSN)r get_start_pos_of_prefixr-s r0 _split_prefixzPythonLeaf._split_prefix|sD$">">"@AAr2c|j}|-|jdk(r|jdvr|j}|2t|j}|j t |z dzdfS|jS)z[ Basically calls :py:meth:`parso.tree.NodeOrLeaf.get_start_pos_of_prefix`. error_leaf)INDENTDEDENT ERROR_DEDENTr'r)get_previous_leafr) token_typer prefixlinelenr=)r- previous_leafliness r0rFz"PythonLeaf.get_start_pos_of_prefixs ..0  $););|)K!,,0TT);;=M   ,E99s5z)A-q0 0$$$r2N)r3r4r5r6rHrFr r2r0rCrCysIB%r2rCc4eZdZdZdZedeeeffdZy)_LeafWithoutNewlinesz. Simply here to optimize performance. r returnc^|j|jt|jzfSrE)rQcolumnrRvaluerGs r0r=z_LeafWithoutNewlines.end_poss"yy$++DJJ777r2N) r3r4r5rAr6propertyrintr=r r2r0rVrVs/I 8sCx88r2rVceZdZdZy)PythonBaseNoder Nr3r4r5r6r r2r0r^r^Ir2r^ceZdZdZy) PythonNoder Nr_r r2r0rbrbr`r2rbceZdZdZy)PythonErrorNoder Nr_r r2r0rdrdr`r2rdceZdZdZy)PythonErrorLeafr Nr_r r2r0rfrfr`r2rfceZdZdZdZdZy) EndMarkerr endmarkerczdt|jdt|jd|jdS)N)r)r3reprrPr=rGs r0__repr__zEndMarker.__repr__s* J  dkk!2DLL  r2N)r3r4r5r6r)rnr r2r0rhrhsI D r2rhceZdZdZdZdZdZy)Newlinez&Contains NEWLINE and ENDMARKER tokens.r newlinec`dt|jdt|jdS)Nrk: rl)r)r3rmrZrGs r0rnzNewline.__repr__s !$Z00$tzz2BCCr2N)r3r4r5rAr6r)rnr r2r0rprps0I DDr2rpc.eZdZdZdZdZdZddZd dZy) Nameza A string. Sometimes it is important to know if the string belongs to a name or not. r:r c dt|jd|jd|jd|jd S)Nrkrs@,rl)r)r3rZrQrYrGs r0rnz Name.__repr__s,#':#6#6 #'99dkk; ;r2c*|j|duS)z< Returns True if the name is being defined. )include_setitemN)get_definitionr-rzs r0 is_definitionzName.is_definitions""?"C4OOr2ch|j}|j}|dvr||jk(r|Sy|dk(r |jdk(r |jSy|]|jdk(ry|jtvr,||j |vr|S|r|jt vr|Sy|j}|]y)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_alwaysrzr.type_s r0r{zName.get_definitions{{  + +tyy   O #((*d2{{"yyG#yy11411/BBK%$))x*?K;;Dr2NF)FF) r3r4r5rAr)r6rnr}r{r r2r0rurus# DI;P r2ruceZdZdZy)Literalr Nr_r r2r0rrr`r2rceZdZdZdZy)Numbernumberr Nr3r4r5r)r6r r2r0rrs DIr2rc*eZdZdZdZedZdZy)Stringr(r c`tjd|jjdS)Nz \w*(?=[\'"])r)rematchrZgrouprGs r0 string_prefixzString.string_prefixs"xx4::1==r2ctjd|jtj}|j ddt |j d S)Nz('{3}|"{3}|'|")(.*)$)flagsr')rsearchrZDOTALLrrR)r-rs r0 _get_payloadzString._get_payloadsI ' JJ))  {{1~3EKKN 3344r2N)r3r4r5r)r6r[rrr r2r0rrs# DI >>5r2rceZdZdZdZdZy) FStringStringx f-strings contain f-string expressions and normal python strings. These are the string parts of f-strings. fstring_stringr Nr3r4r5rAr)r6r r2r0rrs DIr2rceZdZdZdZdZy) FStringStartr fstring_startr Nrr r2r0rrs DIr2rceZdZdZdZdZy) FStringEndr fstring_endr Nrr r2r0rr s DIr2rceZdZdZdZdZy)_StringComparisonMixinr cHt|tr|j|k(S||uS)ze Make comparisons with strings easy. Improves the readability of the parser. )r;strrZr-others r0__eq__z_StringComparisonMixin.__eq__,s' eS !::& &u}r2c,t|jSrE)hashrZrGs r0__hash__z_StringComparisonMixin.__hash__6DJJr2N)r3r4r5r6rrr r2r0rr)sI r2rceZdZdZdZy)Operatoroperatorr Nrr r2r0rr:s DIr2rceZdZdZdZy)Keywordkeywordr Nrr r2r0rr?s DIr2rcJeZdZdZdZfdZdZdZdZdZ 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 c$t||yrEsuper__init__r-r* __class__s r0rzScope.__init__L "r2c$|jdS)z9 Returns a generator of `funcdef` nodes. r$_search_in_scoperGs r0 iter_funcdefszScope.iter_funcdefsOs$$Y//r2c$|jdS)z: Returns a generator of `classdef` nodes. r%rrGs r0iter_classdefszScope.iter_classdefsUs$$Z00r2c&|jddS)zO Returns a generator of `import_name` and `import_from` nodes. rrrrGs r0 iter_importszScope.iter_imports[s$$]MBBr2c6fd|jS)Nc3K|D]A}|jvr||jtvs(|jEd{Cy7wrE)r)_FUNC_CONTAINERSr*)r*elementnamesscans r0rz$Scope._search_in_scope..scanbsM# 6<<5(!M<<#33#G$4$4555  66s*A A A A r*)r-rrs `@r0rzScope._search_in_scopeas 6DMM""r2c |jdS)zD Returns the part that is executed by the function. rrGs r0 get_suitezScope.get_suiteks}}R  r2c  |jj}dt|jd|d|j dd|j dd S#t$rd}YIwxYw)Nrkrsrwr-rl)r:rZAttributeErrorr)r3r<r=)r-r:s r0rnzScope.__repr__qs^ 99??D$(:#6#6#'>>!#4dll1oG G D sA A"!A") r3r4r5rAr6rrrrrrrn __classcell__rs@r0rrDs4 I#0 1 C #! Gr2rc6eZdZdZdZdZfdZdZdZxZ 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"c2t||d|_yrE)rrrrs r0rzModule.__init__s "r2c#K|jD]o}|jdk(s|jdk(s#|jD]:}|Dcgc]}|j}}t |dk(s+|ddk(s4|d<qycc}ww)zU :return: A list of future import names. :rtype: list of str rrr __future__r'N)rr)level get_pathsrZrR)r-imppathr:rs r0_iter_future_import_namesz Module._iter_future_import_namess$$& 'Cxx=(SYY!^MMO'D489DTZZ9E95zQ58|+C#Ah' ':s'#B B B  B B 1B :B cv|j ifd|t|_|jS)z Returns all the :class:`Name` leafs that exist in this module. This includes both definitions and references of names. c |j}|D] }| y#t$rA|jdk(r/j|jg}|j |YyYywxYw)Nr:)r*rr) setdefaultrZappend)r.r*childarrdctrecurses r0rz&Module.get_used_names..recursesk'#}}H "*'' &)yyF*!nnTZZ< 4(+)s AA)(A))rUsedNamesMapping)r-rrs @@r0get_used_nameszModule.get_used_namess=    #C ' DM/4D r2) r3r4r5rAr6r)rrrrrs@r0rr{s# !I D '  r2rceZdZdZdZy) Decorator decoratorr Nrr r2r0rrs DIr2rc&eZdZdZedZdZy) ClassOrFuncr c |jdS)zR Returns the `Name` leaf that defines the function or class name. r'rrGs r0r:zClassOrFunc.names }}Qr2c|j}|jdk(r |j}|jdk(rD|jdjdk(r|jdjS|jddSgS)z4 :rtype: list of :class:`Decorator` rrr decoratorsNr')r,r)r*)r-rs r0get_decoratorszClassOrFunc.get_decoratorssxKK >>_ ,!((I >>[ (!!!$))\9 ))!,555 ))"1--Ir2N)r3r4r5r6r[r:rr r2r0rrsI   r2rc0eZdZdZdZdZfdZdZxZS)Classz> Used to store the parsed contents of a python class. r%r c$t||yrErrs r0rzClass.__init__rr2cl|jddk7ry|jddk(ry|jdS)z Returns the `arglist` node that defines the super classes. It returns None if there are no arguments. r(N)rrGs r0get_super_arglistzClass.get_super_arglists; == s "}}Q3&}}Q''r2) r3r4r5rAr)r6rrrrs@r0rrs DI# (r2rc |d}|jdvrt|g|gS|dk(r|gS|jdk(r|g}n |j}g}d}t |dgzdD]l\}}||dk(s|||}|s|ddk(rt |dk(s|ddk(s|ddk(r|D] } || _ ||z }n|jt|||}n|S#t$rgcYSwxYw) 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* enumeraterRr,r) r, argslist_listfirstr* new_childrenstartendrparam_childrenps r0_create_paramsr s-a  zz&&ugv&'' #w :: !wH~~H #Hv$5q9 JC} !)%!4!%a(C/!$^!4!9$21$5$<-a0C7!/.A'-AH.$6 $++E.&,IJE ;  sC CCcneZdZdZdZdZfdZdZdZe dZ dZ d Z d Z d 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|||jd}|jdd}td|Dst |||jddyy)Nrr'rc3<K|]}t|tywrEr;r.0rs r0 z$Function.__init__..-M:eU+M)rrr*anyr )r-r* parametersparameters_childrenrs r0rzFunction.__init__'sb "]]1% (11!B7M9LMM(6zCV(WJ  " %Nr2c4|jdjS)NrrrGs r0_get_param_nodeszFunction._get_param_nodes0s}}Q(((r2ch|jDcgc]}|jdk(s|c}Scc}w)z. Returns a list of `Param()`. r)rr))r-r s r0 get_paramszFunction.get_params3s, 002Haaff6GHHHs//c |jdSNr'rrGs r0r:z Function.name9}}Qr2c2fd|jS)z6 Returns a generator of `yield_expr`. c3 K|D].}|jdvr |j}|Ed{0y7#t$r>|jdk(r,|jjdk(r|jn|YzwxYww)N)r%r$lambdefyield yield_expr)r)r*rrZr,)r*rnested_childrenrs r0rz'Function.iter_yield_exprs..scanAs# 5<<#EE 5&-&6&6O $O444 55&*}}/">>..,>")..0")M *s/B : B8BAB>BBBrr-rs @r0iter_yield_exprszFunction.iter_yield_exprs=s 5 DMM""r2c2fd|jS)z7 Returns a generator of `return_stmt`. c3K|D]`}|jdk(s|jdk(r|jdk(r||jtvsG|jEd{by7w)N return_stmtrrWr)rZ_RETURN_STMT_CONTAINERSr*r*rrs r0rz(Function.iter_return_stmts..scanWsd# 6<<=0"<<94(9R!M<<#::#G$4$4555  6 6A A, A,"A*#A,rr(s @r0iter_return_stmtszFunction.iter_return_stmtsS 6DMM""r2c2fd|jS)zi Returns a generator of `raise_stmt`. Includes raise statements inside try-except blocks c3K|D]`}|jdk(s|jdk(r|jdk(r||jtvsG|jEd{by7w)N raise_stmtrraiser-r/s r0rz'Function.iter_raise_stmts..scanesd# 6<<</"<<94'9Q!M<<#::#G$4$4555  6 6r0rr(s @r0iter_raise_stmtszFunction.iter_raise_stmtsar2r2c:t|jdduS)zK :return bool: Checks if a function is a generator or not. N)nextr)rGs r0 is_generatorzFunction.is_generatorosD))+T2$>>r2c |jddk(r|jdS|jddk(sJy#t$rYywxYw)zW Returns the test node after `->` or `None` if there is no annotation. rz->r&N)r*rrGs r0 annotationzFunction.annotationusS  }}Q4'}}Q''==#s* **  s 88 AA)r3r4r5rAr)r6rrrr[r:r)r1r7r:r=rrs@r0rrsa  DIX)I   #, # #?   r2rcVeZdZdZdZdZfdZedZdZ 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 |||jddyy)Nr'c3<K|]}t|tywrErrs r0rz"Lambda.__init__..rr)rrrr*rr )r-r*rrs r0rzLambda.__init__sR h&x0"mmAb1M9LMM"07J"KDMM!B Nr2ctd)zN Raises an AttributeError. Lambdas don't have a defined name. zlambda is not named.)rrGs r0r:z Lambda.names 344r2c |jddS)Nr'rArrGs r0rzLambda._get_param_nodess}}Qr""r2cy)zA Returns `None`, lambdas don't have annotations. Nr rGs r0r=zLambda.annotations r2cPd|jjd|jdS)Nrkrwrl)rr3r<rGs r0rnzLambda.__repr__s NN33T^^DDr2) r3r4r5rAr)r6rr[r:rr=rnrrs@r0r?r?sM  DIL55 # Er2r?ceZdZdZy)Flowr Nr_r r2r0rHrHr`r2rHc&eZdZdZdZdZdZdZy)IfStmtr r c#xKt|jD]\}}|dvs |j|dz yw)z E.g. returns all the `test` nodes that are named as x, below: if x: pass elif x: pass )elififr'N)rr*)r-ir/s r0get_test_nodeszIfStmt.get_test_nodess?dmm, +DAqN"mmAE** +s ::c|j}tt|jD]&}|j|ks||jkry|cSy)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<reversedlistrOr=)r-r.r< check_nodes r0get_corresponding_test_nodez"IfStmt.get_corresponding_test_nodesV NN "4(;(;(=#>? &J##i/z111&% &r2ch|jD]#}|dk(s |j|jkDs#yy)z; Checks if a node is defined after `else`. elseTF)r*r<)r-r.r/s r0is_node_after_elsezIfStmt.is_node_after_elses6 AF{>>AKK/  r2N)r3r4r5r)r6rOrTrWr r2r0rJrJs DI +& r2rJceZdZdZdZy) WhileStmtrr Nrr r2r0rYrY DIr2rYc"eZdZdZdZdZddZy)ForStmtrr c |jdS)zE Returns the input node ``y`` from: ``for x in y:``. rrrGs r0 get_testlistzForStmt.get_testlists}}Qr2c4t|jd|Sr _defined_namesr*r|s r0rzForStmt.get_defined_namesdmmA.@@r2Nr)r3r4r5r)r6r^rr r2r0r\r\s DI Ar2r\ceZdZdZdZdZy)TryStmtrr c#K|jD]-}|jdk(r|jd$|dk(s*d/yw)z Returns the ``test`` nodes found in ``except_clause`` nodes. Returns ``[None]`` for except clauses without an exception given. rr'exceptNr*r)r-r.s r0get_except_clause_testszTryStmt.get_except_clause_testssC MM DyyO+mmA&&!  s 6AAN)r3r4r5r)r6rir r2r0rdrds DI r2rdc"eZdZdZdZddZdZy)WithStmtrr cg}|jdddD].}|jdk(s|t|jd|z }0|S)z} Returns the a list of `Name` that the with statement defines. The defined names are set after `as`. r'rAr with_item)r*r)ra)r-rzrrms r0rzWithStmt.get_defined_namessX qAv. PI~~, (:(:1(=OO P r2c\|jd}| td|jdS)Nrmz2The name is not actually part of a with statement.r)r ValueErrorr*)r-r:r.s r0get_test_node_from_namez WithStmt.get_test_node_from_names2##K0 <QR R}}Qr2Nr)r3r4r5r)r6rrpr r2r0rkrks DI  r2rkc"eZdZdZdZdZdZy)Importr c |j|}|jD]}||vs|d|j|dzcSt d#t$rYHwxYw)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)_aliasesKeyErrorrr+ro)r-r:rs r0get_path_for_namezImport.get_path_for_namest  ==?4(DNN$ 3Dt|1TZZ-122 3FGG    sA AAcy)NFr rGs r0 is_nestedzImport.is_nested/sr2c&|jddk(S)NrrrrGs r0is_star_importzImport.is_star_import2s}}R C''r2N)r3r4r5r6rvrxrzr r2r0rrrrsIH"(r2rrcDeZdZdZdZd dZdZdZedZ dZ dZ y ) ImportFromrr c\|jDcgc] \}}|xs| c}}Scc}}w)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. )_as_name_tuples)r-rzr:aliass r0rzImportFrom.get_defined_names:s+ 261E1E1GH+$  HHHs(cBtd|jDS)z-Mapping from alias to its corresponding name.c3.K|] \}}|||fywrEr )rr:rs r0rz&ImportFrom._aliases..Ds%*kdE(DM*s)dictr~rGs r0rtzImportFrom._aliasesBs$*T5I5I5K** *r2c|jddD]}|dvsnjdk(r|jdddS|dk(rgS|gS)Nr'.z... dotted_namerimportrg)r-ns r0get_from_nameszImportFrom.get_from_namesGsZqr" A $  66] "::cc? " (]I3Jr2cpd}|jddD]!}|dvr|t|jz } |S|S)&The level parameter of ``__import__``.rr'Nrr*rRrZ)r-rrs r0rzImportFrom.levelRsLqr" AL QWW%    r2c# K|jd}|dk(r|jd}n|dk(ry|jdk(r|jddd}n|g}|D],}|jdk(r|df|jddd.yw)NrrrArimport_as_namesrr:rg)r-lastas_namesas_names r0r~zImportFrom._as_name_tuples]s}}R  3;==$D S[  99) )}}SqS)HvH ,G||v%tm#&&ss++  ,sBBc|j}|jddk(r|gS|jDcgc] \}}||gz c}}Scc}}w)z The import paths defined in an import statement. Typically an array like this: ``[, ]``. :return list of list of Name: rr)rr*r~)r-dottedr:rs r0rzImportFrom.get_pathsnsQ$$& ==  #8O373G3G3IJKD%$JJJsA Nr) r3r4r5r)r6rrtrr[rr~rr r2r0r|r|6s; DII* ," Kr2r|cHeZdZdZdZdZd dZedZdZ dZ dZ d Z y ) ImportNamezBFor ``import_name`` nodes. Covers normal imports without ``from``.rr cb|jDcgc]\}}|xs|dc}}Scc}}w)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. r_dotted_as_names)r-rzrrs r0rzImportName.get_defined_namess1 594I4I4KL[T5 a LLLs+cy)rrr rGs r0rzImportName.levelsr2cT|jDcgc]\}}| c}}Scc}}wrErr-rrs r0rzImportName.get_pathss#(,(=(=(?@u@@@s $c#<K|jd}|jdk(r|jddd}n|g}|D]_}|jdk(r|jd}|jd}nd}|jdk(r|g|fJ|jddd|fayw)z9Generator of (list(path), alias) where alias may be None.r'dotted_as_namesNrdotted_as_namerr:rg)r-rrrrs r0rzImportName._dotted_as_namess--*   #4 4&//!4H'(H 3G||//((+!**1-||v%i&&&&ss+U22 3sBBc t|jDcgc]\}}|t|dkDrdc}}Scc}}w)z This checks for the special case of nested imports, without aliases and from statement:: import foo.bar r')boolrrRrs r0rxzImportName.is_nestedsF$*?*?*A8;4}TQ89 98s= cBtd|jDS)z= :return list of Name: Returns all the alias c34K|]\}}| ||dfyw)Nrr )rrrs r0rz&ImportName._aliases..s**+$(DH%*s)rrrGs r0rtzImportName._aliasess&*9N9N9P** *r2Nr) r3r4r5rAr)r6rr[rrrrxrtr r2r0rr|s>L DIMA3(9*r2rc<eZdZdZdZedZedZddZy)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|jzS)z Keyword statements start with the keyword and end with `_stmt`. You can crosscheck this with the Python grammar. z%s_stmt)rrGs r0r)zKeywordStatement.types 4<<''r2c4|jdjSNr)r*rZrGs r0rzKeywordStatement.keywords}}Q%%%r2c|j}|dk(rt|jd|S|dvr|jdddSgS)Ndelr')globalnonlocalr)rrar*)r-rzrs r0rz"KeywordStatement.get_defined_namessL,, e !$--"2OD D , ,==A& & r2Nr) r3r4r5rAr6r[r)rrr r2r0rrs9I ((&&r2rc eZdZdZedZy) AssertStmtr c |jdSr rrGs r0 assertionzAssertStmt.assertionr!r2N)r3r4r5r6r[rr r2r0rrsI   r2rceZdZdZdZy) GlobalStmtr c&|jdddS)Nr'rrrGs r0get_global_nameszGlobalStmt.get_global_namess}}QTT""r2N)r3r4r5r6rr r2r0rrs I#r2rceZdZdZy) ReturnStmtr Nr_r r2r0rrr`r2rceZdZdZdZy) YieldExprr&r Nrr r2r0rrrZr2rcg}|jdvr(|jdddD]}|t||z }|S|jdvr|t|jd|z }|S|jdvr|jddk7r|jd }|jd d k(r |j|jd|S|jd d k(rl|rj|jddd D]U}|jd k(r!|j|jd|S|jdk(sC|j||S|S|j||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_exprrA**rrr[trailerr:)r)r*rar)currentrzrrrr.s r0raras E||VV%%cc* >"a'NN1%E ==A&&&sA A*"A(#A*Nr)r3r4r5r)r6rrrr r2r0rr s DI  'r2rceZdZdZddZy) NamedExprrc4t|jd|Srr`r|s r0rzNamedExpr.get_defined_names9rbr2Nr)r3r4r5r)rr r2r0rr6s DAr2rceZdZdZdZdfd ZedZedZedZ dZ edZ dd Z ed Z d Zdfd Zd ZxZS)rz 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. rc2t||||_yrE)rrr,)r-r*r,rs r0rzParam.__init__Es " r2cT|jd}|dvrt|jSy)zc Is `0` in case of `foo`, `1` in case of `*foo` or `2` in case of `**foo`. rrrrrs r0 star_countzParam.star_countIs,  a  K u{{# #r2c|jddk(} |jdt|z dk(r|jdt|z Sy#t$rYywxYw)z{ The default is the test node that appears after the `=`. Is `None` in case no default is present. rrxrArN)r*r\r)r- has_commas r0defaultz Param.defaultTse MM"%,  }}R#i.01S8}}R#i.%8999  s8A AAc|j}|jdk(r?|jddk(sJt|jdk(sJ|jd}|Sy)zz The default is the test node that appears after `:`. Is `None` in case no annotation is present. rr'r&rrN)_tfpdefr)r*rR)r-rr=s r0r=zParam.annotationas`  ;;( "??1%, ,,v'1, ,,+J r2cTt|jddv}|j|S)z1 tfpdef: see e.g. grammar36.txt. rr)r\r*)r-offsets r0rz Param._tfpdefps+T]]1%45}}V$$r2c|jjdk(r|jjdS|jS)z/ The `Name` leaf of the param. rr)rr)r*rGs r0r:z Param.namews; <<>  ( *<<>**1- -<<> !r2c|jgSrE)r:r|s r0rzParam.get_defined_namess {r2cZ|jjj|} |jjjd}||kDr|dz} |jjjd}||kDr|dz}|dz S#t$rY@wxYw#t$rY|dz SwxYw)zB Property for the positional index of a paramter. rrrr')r,r*r+ro)r-r+keyword_only_indexs r0position_indexzParam.position_indexs  $$**40 !%!5!5!;!;C!@ ))  !%!5!5!;!;C!@ )) qy     qy s#/B /B BB B*)B*c&|jddS)z= Returns the function/lambda of a parameter. r$r$)r rGs r0get_parent_functionzParam.get_parent_functions##Iy99r2c~|rt||S|j}|ddk(r|dd}|j||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. rrxN)include_prefix)rget_coder*_get_code_for_children)r-r include_commar*rs r0rzParam.get_codesV 7#N3 3== B<3 }H** )+  r2c|jdnd|jjz}dt|jdt |j |zdS)Nrz=%srkrsrl)rrr)r3rr)r-rs r0rnzParam.__repr__sI ,"%$,,:O:O:Q2Q!$Z00#dlln2E2OPPr2rEr)TT)r3r4r5rAr)rr[rrr=rr:rrrrrnrrs@r0rr=s D    %""*:  $Qr2rceZdZdZdZddZy) SyncCompForrr c4t|jd|S)zN Returns the a list of `Name` that the comprehension defines. r'r`r|s r0rzSyncCompFor.get_defined_namess dmmA.@@r2Nr)r3r4r5r)r6rr r2r0rrs DIAr2rc4eZdZdZdZdZdZdZdZdZ y) rzO This class exists for the sole purpose of creating an immutable dict. c||_yrE_dict)r-rs r0rzUsedNamesMapping.__init__s  r2c |j|SrEr)r-keys r0 __getitem__zUsedNamesMapping.__getitem__szz#r2c,t|jSrE)rRrrGs r0__len__zUsedNamesMapping.__len__s4::r2c,t|jSrE)iterrrGs r0__iter__zUsedNamesMapping.__iter__rr2ct|SrE)idrGs r0rzUsedNamesMapping.__hash__s $xr2c ||uSrEr rs r0rzUsedNamesMapping.__eq__s u}r2N) r3r4r5rArrrrrrr r2r0rrs% r2r)JrArcollections.abcr ImportError collectionstypingr parso.treerrrrr r parso.python.prefixr parso.utilsr set_FLOW_CONTAINERSr.rrrrr8rCrVr^rbrdrfrhrprurrrrrrrrrrrrrrr rr?rHrJrYr\rdrkrrr|rrrrrrrarrrrCompForrr r2r0r s*X $'RR,#<=w 67:JJ:  }- .8,%d%08:8[(dk9i $ DjD1 1hjW 5W5"J:  "#%; "$: 4GNN4Gn3 U3 l %6(K(0*Zj{jZ*EX*EZ>*T*Z Ad A d   t .(^(6CKCKL8*8*v~> ! #!#! :('~~('VAAwQNwQt A. A wq$$##$sI11 J?J