+
    iJ                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
HtHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHtHtHtHtHtHt ^ RIHtHt ^ R	IHtH t  ^ R
I!H"t"H#t#H$t$ ]'       d   ^ RI%H&t& Rt'Rt(]'       d   ]PR                  ! RR]*4       ] '       d   ]PR                  ! RR]*4       R R lt+R R lt, ! R R]PZ                  4      t.R R lt/R%R R llt0R R lt1R R lt2R&R R  llt3R&R! R" llt4R'R# R$ llt5R# )(zThe AstroidBuilder makes astroid from living object and / or from _ast.

The builder is not thread safe and can't be used to parse different sources
at the same time.
)annotationsN)
CollectionIteratorSequence)TextIOWrapper)detect_encoding)TYPE_CHECKINGcast)basesmodutilsnodesraw_building	rebuilderutil)ParserModuleget_parser_module)
PY312_PLUS
PY314_PLUS)AstroidBuildingErrorAstroidSyntaxErrorInferenceErrorAstroidManager__z#@ignorez.*invalid escape sequencez('(return|continue|break)' in a 'finally'c                    V ^8  d   QhRRRR/# )   filenamestrreturnztuple[TextIOWrapper, str, str] )formats   "1/usr/lib/python3/dist-packages/astroid/builder.py__annotate__r#   1   s     " "s "'E "    c                    \        V R 4      ;_uu_ 4       p\        VP                  4      ^ ,          pRRR4       \        V RXR7      pVP                  4       pW2V3#   + '       g   i     L2; i)rbN)newlineencoding)openr   readlineread)r   byte_streamr(   streamdatas   &    r"   open_source_filer/   1   sX    	h		";#7#78; 
(D8<F;;=DT!!	 
	s   AA,	c               $    V ^8  d   QhRRRRRR/# )r   nodeznodes.ClassDefattrname
str | Noner   boolr    )r!   s   "r"   r#   r#   :   s!     - -> -Z -D -r$   c                     V P                  4       pV'       d"   Y Uu0 uF  q3P                  kK  	  up9  d   R # T P                  4       R8g  # u upi   \         d     L%i ; i)Fzbuiltins.object)slotsvalueNotImplementedErrorqname)r1   r2   r6   slots   &&  r"   _can_assign_attrr;   :   s^    

 XU%CUTjjU%CC::<,,, &D  s   A AA! A!c                     a  ] tR t^EtRtRR V 3R llltRR R lltRR R lltRR R	 lltR
 R lt	R R lt
R R ltR R ltRtV ;t# )AstroidBuildera1  Class for building an astroid tree from source code or from a live module.

The param *manager* specifies the manager class which should be used. The
param *apply_transforms* determines if the transforms should be
applied after the tree was built from source or from a live object,
by default being True.
c               $    V ^8  d   QhRRRRRR/# )r   managerr   apply_transformsr4   r   Noner    )r!   s   "r"   r#   AstroidBuilder.__annotate__N   s"          $  RV  r$   c                	   < \         SV `  V4       W n        \        P                  P
                  '       g   VP                  4        R # R # N)super__init___apply_transformsr   InspectBuilderbootstrapped	bootstrap)selfr?   r@   	__class__s   &&&r"   rF   AstroidBuilder.__init__N   s9    !!1**777 8r$   c               $    V ^8  d   QhRRRRRR/# )r   moduleztypes.ModuleTypemodnamer3   r   nodes.Moduler    )r!   s   "r"   r#   rB   T   s$      &1;	r$   c                   Rp\        VRR4      p\        VRR4      pV'       dC   T;'       g    VP                  pVP                  V4      pV'       d   V P                  WbVR7      pVf   Ve   \        P
                  P                  \        P                  ! V4      4      w  rxVR9   dF   \        P
                  P                  VR,           4      '       d   V P                  VR,           V4      pVfA   V P                  WVR7      pV P                  '       d   V P                  P                  V4      p\        V\         P"                  4      '       g   Q hV# )z/Build an astroid from a living module instance.N__file__
__loader__)path.pyrP   rU   >   rV   .pyc.pyo)getattr__name__
get_sourcestring_buildosrU   splitextr   _path_from_filenameexists
file_buildinspect_buildrG   _managervisit_transforms
isinstancer   Module)	rK   rO   rP   r1   rU   loadersourcepath_exts	   &&&      r"   module_buildAstroidBuilder.module_buildT   s    vz40t4 00G&&w/F((t(D<D,))(*F*Ft*LMJE--"''..2O2Ouu}g>< %%fD%ID%%% }}55d;$----r$   c               $    V ^8  d   QhRRRRRR/# )r   rU   r   rP   r3   r   rQ   r    )r!   s   "r"   r#   rB   q   s!     $? $?s $?Z $?< $?r$   c                    \        V4      w  r4pT;_uu_ 4        Tf'    RP                  \        P                  ! T4      4      pT P                  YRT4      w  rxT P!                  YxT4      uuRRR4       #   \         d   p\        RTTTR7      ThRp?i\        \        3 d   p\        RTTTR7      ThRp?i\         d   p\        RTR7      ThRp?ii ; i  \         dG    \        P                  P                  \        P                  P                  T4      4      ^ ,          p Li ; i  + '       g   i     R# ; i)ziBuild astroid from a source code file (i.e. from an ast).

*path* is expected to be a python source file
z#Unable to load file {path}:
{error})rP   rU   errorNzBPython 3 encoding specification error or unknown encoding:
{error}z.Wrong or no encoding specified for {filename}.)r   .)r/   OSErrorr   SyntaxErrorLookupErrorr   UnicodeErrorjoinr   modpath_from_fileImportErrorr^   rU   r_   basename_data_build_post_build)	rK   rU   rP   r-   r(   r.   excrO   builders	   &&&      r"   rb   AstroidBuilder.file_buildq   s2   
	%5d%;"Fd* VJ!hhx'A'A$'GHG #..tdCOF##FX> V)  	&6	
  [) 	$   	&@4	 # J gg..rww/?/?/EFqIGJ VVsj   A5 D,%C%D,5C BC#C$B44CCCCAD)&D,(D))D,,D=	c               (    V ^8  d   QhRRRRRRRR/# )r   r.   r   rP   rU   r3   r   rQ   r    )r!   s   "r"   r#   rB      s,     : ::"%:2<:	:r$   c                z    V P                  WV4      w  rEVP                  R4      Vn        V P                  WER4      # )z&Build astroid from source code string.zutf-8)rz   encode
file_bytesr{   )rK   r.   rP   rU   rO   r}   s   &&&&  r"   r]   AstroidBuilder.string_build   s<     **4$? KK099r$   c               (    V ^8  d   QhRRRRRRRR/# )r   rO   rQ   r}   zrebuilder.TreeRebuilderr(   r   r   r    )r!   s   "r"   r#   rB      s,      "-DPS	r$   c                   W1n         V P                  P                  V4       VP                   FW  w  rEVP                  R8X  d1   VP
                   F   w  rgVP                  P                  V4       K"  	  V P                  WE4       KY  	  VP                   F  pV P                  V4       K  	  V P                  '       d   V P                  P                  V4      pV# )zAHandles encoding and delayed nodes after a module has been built.
__future__)file_encodingrd   cache_module_import_from_nodesrP   namesfuture_importsaddadd_from_names_to_locals_delayed_assattrdelayed_assattrrG   re   )	rK   rO   r}   r(   	from_nodeglobal_namessymbol_delayeds	   &&&&     r"   r{   AstroidBuilder._post_build   s      (""6*'.'A'A#I  L0!*IF))--f5 "1)))B	 (B //G  ) 0 !!!]]33F;Fr$   c               (    V ^8  d   QhRRRRRRRR/# )r   r.   r   rP   rU   r3   r   z,tuple[nodes.Module, rebuilder.TreeRebuilder]r    )r!   s   "r"   r#   rB      s,      "%-7	5r$   c           	     &    \        VRVR7      w  rETe!   \        P                  P                  T4      pMRpTP                  R4      '       d	   TRR	 pRpMRTRJ;'       dG    \        P                  P                  \        P                  P                  T4      4      ^ ,          R8H  p\        P                  ! T P                  YQ4      p	T	P                  YBYx4      p
Y3#   \        \        \        \        3 d   p\        RTTTTR7      ThRp?ii ; i)
z4Build tree node from data and add some informations.T)type_commentsrP   z#Parsing Python code failed:
{error})ri   rP   rU   rp   Nz<?>z	.__init__rF   i)_parse_string	TypeError
ValueErrorrs   MemoryErrorr   r^   rU   abspathendswithr_   ry   r   TreeRebuilderrd   visit_module)rK   r.   rP   rU   r1   parser_moduler|   	node_filepackager}   rO   s   &&&&       r"   rz   AstroidBuilder._data_build   s   	"/D'#D -IIK((crlGG D  N NGG$$RWW%5%5d%;<Q?:M  ))$--M%%dYH/ :{K@ 	$6 	s   C D:DDc               $    V ^8  d   QhRRRRRR/# )r   r1   znodes.ImportFromglobal_namezCollection[str]r   rA   r    )r!   s   "r"   r#   rB      s$     !1 !1$!13B!1	!1r$   c                  a R V3R llpSP                   '       g   Q hSP                  4       pSP                   F  w  rVVR8X  dN    SP                  4       pTP                  4        F&  pYR9   d   T! YE4       K  T! SP                   T4       K(  	  KY  T;'       g    TpWR9   d   V! WE4       Ku  V! SP                   V4       K  	  R#   \         d     K  i ; i)zUStore imported names to the locals.

Resort the locals if coming from a delayed node
c               $    V ^8  d   QhRRRRRR/# )r   parent_or_rootnodes.NodeNGnamer   r   rA   r    )r!   s   "r"   r#   =AstroidBuilder.add_from_names_to_locals.<locals>.__annotate__   s!     	: 	:l 	:# 	:$ 	:r$   c                   < V P                  VS4       V P                  4       P                  V,          p\        '       d&   \	        \
        \        P                  ,          V4      pVP                  R  R7       R# )c                .    V P                   ;'       g    ^ # )    )
fromlineno)ns   &r"   <lambda>LAstroidBuilder.add_from_names_to_locals.<locals>.add_local.<locals>.<lambda>   s    q||'8'8q'8r$   )keyN)		set_localscopelocalsr   r	   listr   NodeNGsort)r   r   my_listr1   s   && r"   	add_local:AstroidBuilder.add_from_names_to_locals.<locals>.add_local   sU    $$T40$**,33D9G}tELL17;LL8L9r$   *N)parentrootr   do_import_moduler   public_names)rK   r1   r   r   rO   r   asnameimporteds   &f&     r"   r   'AstroidBuilder.add_from_names_to_locals   s    	: 	: {{{{ JJLDs{#446H %113D*!&/!$++t4	 4 ~~&f+dkk40! ' , s   C		CCc                    V ^8  d   QhRRRR/# )r   r1   znodes.AssignAttrr   rA   r    )r!   s   "r"   r#   rB      s     $ $$4 $ $r$   c                   ^ RI Hp  VP                  P                  4        EF=  p\	        V\
        P                  4      '       d   K&   \        V4      \        P                  VP                  09   d7   VP                  pVP                  p\        W1P                  4      '       g   K  M\	        V\        P                  4      '       d   K  \	        V\        P                  \
        P                  34      '       d   K  VP                   '       d   VP                  pMVP"                  p VP'                  VP                  . 4      pW9   d   EK,  VP)                  V4       EK@  	  R#   \$         d     EKS  i ; i  \*         d     R# i ; i)zSVisit an AssignAttr node.

This adds name to locals and handle members definition.
)objectsN)astroidr   exprinferrf   r   UninferableBasetyper
   InstanceExceptionInstance_proxiedinstance_attrsr;   r2   Proxyis_functionr   AttributeError
setdefaultappendr   )rK   r1   r   inferrediattrsvaluess   &&    r"   r   AstroidBuilder.delayed_assattr   s-   
 	$	 IIOO-h(<(<==H~%..':S:S)TT#+#4#4!)!8!8/--HH$  I#Henn== !#Hu{{D<P<P.QRR !---!)!8!8!)  **4=="=>d#5 .( &   		sm   A E9 	AE&&E9 ) E&	E9 0E&;E9 =E&E&E9 E&(<E9 &E61E9 5E66E9 9FF)rG   )TrD   ) N)r[   
__module____qualname____firstlineno____doc__rF   rl   rb   r]   r{   rz   r   r   __static_attributes____classcell__)rL   s   @r"   r=   r=   E   s=       :$?L:*B!1F$ $r$   r=   c               $    V ^8  d   QhRRRRRR/# )r   r   r   rU   zSequence[str]r   rQ   r    )r!   s   "r"   r#   r#     s!       M l r$   c                \    \         P                  ! WR R7      pVP                  . RR7       V# )T)rU   r   N)bodydoc_node)r   rg   postinit)r   rU   rO   s   && r"   build_namespace_package_moduler     s'    \\$48F
OOdO+Mr$   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   coder   module_namerU   r3   r@   r4   r   rQ   r    )r!   s   "r"   r#   r#   %  sA     F F
FF F 	F
 Fr$   c                    ^ RI Hp \        P                  ! V 4      p \	        V! 4       VR7      pVP                  WVR7      # )a[  Parses a source string in order to obtain an astroid AST from it.

:param str code: The code for the module.
:param str module_name: The name for the module, if any
:param str path: The path for the module
:param bool apply_transforms:
    Apply the transforms for the give code. Use it if you
    don't want the default transforms to be applied.
r   )r@   rW   )astroid.managerr   textwrapdedentr=   r]   )r   r   rU   r@   r   r}   s   &&&&  r"   parser   %  s;      /??4 D^-@PQGEEr$   c                    V ^8  d   QhRRRR/# )r   r1   r   r   zIterator[nodes.NodeNG]r    )r!   s   "r"   r#   r#   <  s     &3 &3| &30F &3r$   c              #    "   \        V \        P                  4      '       Ed!   \        V P                  \        P                  4      '       d   V P                  P
                  \        8X  d   V P                  '       d   V P                  ^ ,          pV P                  '       g   Q hV P                  Vn        V P                  P                   Fm  p\        V P                  V4      p\        V\        4      '       d"   \        V4       F  w  rEWPJ g   K  WV&   K  	  KP  W0J g   KW  \        V P                  W!4       Ko  	  Vx  R# V P                  4        F  p\        V4       Rj  xL
  K  	  R#  L
5i)a  Find expressions in a call to _TRANSIENT_FUNCTION and extract them.

The function walks the AST recursively to search for expressions that
are wrapped into a call to _TRANSIENT_FUNCTION. If it finds such an
expression, it completely removes the function call node from the tree,
replacing it by the wrapped expression inside the parent.

:param node: An astroid node.
:type node:  astroid.bases.NodeNG
:yields: The sequence of wrapped expressions on the modified tree
expression can be found.
N)rf   r   CallfuncNamer   _TRANSIENT_FUNCTIONargsr   _astroid_fieldsrZ   r   	enumeratesetattrget_children_extract_expressions)r1   	real_exprr   childidxcompound_childs   &     r"   r   r   <  s      	4$$tyy%**--IINN11IIIIIaL	{{{{;;	 KK//DDKK.E%&&+4U+;'C%-%.c
 ,< T5 0 &&(E+E222 )2s,   A<E2?$E2$A*E2E2$AE2%E0&E2c               $    V ^8  d   QhRRRRRR/# )r   r1   r   lineintr   nodes.NodeNG | Noner    )r!   s   "r"   r#   r#   e  s"        ,  c  >Q  r$   c                "   \        V \        P                  \        P                  \        P                  34      '       d   V P
                  pMV P                  pW!8X  d   V # V P                  4        F  p\        W14      pV'       g   K  Vu # 	  R# )a  Extracts the statement on a specific line from an AST.

If the line number of node matches line, it will be returned;
otherwise its children are iterated and the function is called
recursively.

:param node: An astroid node.
:type node: astroid.bases.NodeNG
:param line: The line number of the statement to extract.
:type line: int
:returns: The statement on the line, or None if no statement for the line
  can be found.
:rtype:  astroid.bases.NodeNG or None
N)	rf   r   ClassDefFunctionDef	MatchCaser   linenor   _find_statement_by_line)r1   r  	node_liner   results   &&   r"   r	  r	  e  sq     $):):EOOLMM
 OO	KK	""$(56M %
 r$   c               $    V ^8  d   QhRRRRRR/# )r   r   r   r   r   z!nodes.NodeNG | list[nodes.NodeNG]r    )r!   s   "r"   r#   r#     s'     S" S"s S" S"6W S"r$   c                   R R lp. p\        V P                  4       4       FH  w  rEVP                  4       P                  \        4      '       g   K0  VP                  V^,           4       KJ  	  \        WR7      pVP                  '       g   \        R4      h. pV'       d   V Uu. uF  p\        We4      NK  	  ppVP                  \        V4      4       V'       g#   VP                  VP                  R,          4       V Uu. uF
  q! V4      NK  	  ppV Uu. uF
  qf   K  VNK  	  p	p\        V	4      ^8X  d
   V	^ ,          # V	# u upi u upi u upi )a  Parses some Python code as a module and extracts a designated AST node.

Statements:
 To extract one or more statement nodes, append #@ to the end of the line

 Examples:
   >>> def x():
   >>>   def y():
   >>>     return 1 #@

   The return statement will be extracted.

   >>> class X(object):
   >>>   def meth(self): #@
   >>>     pass

  The function object 'meth' will be extracted.

Expressions:
 To extract arbitrary expressions, surround them with the fake
 function call __(...). After parsing, the surrounded expression
 will be returned and the whole AST (accessible via the returned
 node's parent attribute) will look like the function call was
 never there in the first place.

 Examples:
   >>> a = __(1)

   The const node will be extracted.

   >>> def x(d=__(foo.bar)): pass

   The node containing the default argument will be extracted.

   >>> def foo(a, b):
   >>>   return 0 < __(len(a)) < b

   The node containing the function call 'len' will be extracted.

If no statements or expressions are selected, the last toplevel
statement will be returned.

If the selected statement is a discard statement, (i.e. an expression
turned into a statement), the wrapped expression is returned instead.

For convenience, singleton lists are unpacked.

:param str code: A piece of Python code that is parsed as
a module. Will be passed through textwrap.dedent first.
:param str module_name: The name of the module.
:returns: The designated node from the parse tree, or a list of nodes.
c                    V ^8  d   QhRRRR/# )r   r1   r  r   r    )r!   s   "r"   r#   "extract_node.<locals>.__annotate__  s      * /B r$   c                ^    \        V \        P                  4      '       d   V P                  # V # rD   )rf   r   Exprr7   )r1   s   &r"   _extractextract_node.<locals>._extract  s"    dEJJ''::r$   )r   z"Empty tree, cannot extract from it)r   
splitlinesstripr   _STATEMENT_SELECTORr   r   r   r   r	  extendr   len)
r   r   r  requested_linesr   r  tree	extractedr1   extracted_without_nones
   &&        r"   extract_noder    s   l "$Ot01	::<  !455""37+ 2 /D999=>>+-IETU_T,T8_	U )$/02',56ID$II6/8MytddyM
!"a'%a((!! V 7Ms   %EEE#Ec               $    V ^8  d   QhRRRRRR/# )r   r   r   r   r   r   r    )r!   s   "r"   r#   r#     s!      s  l r$   c                Z    \        W4      p\        V\        4      '       d
   V^ ,          # V# )zDCall extract_node while making sure that only one value is returned.)r  rf   r   )r   r   rets   && r"   _extract_single_noder"    s'    
t
)C#t1vJr$   c               (    V ^8  d   QhRRRRRRRR/# )	r   r.   r   r   r4   rP   r3   r   ztuple[ast.Module, ParserModule]r    )r!   s   "r"   r#   r#     s,     ! !
!"!4>!$!r$   c                N   \        VR 7      p VP                  V R,           WR7      pWC3#   \         do   p\        P                  ! RTP
                  ;'       g    R4      pT'       d	   T'       g   h \        RR 7      pTP                  T R,           RR 7      p Rp?YC3# Rp?ii ; i))r   
)r   r   z	#\s+type:r   FN)r   r   rs   researchtext)r.   r   rP   r   parsedr|   type_annot_relateds   &&&    r"   r   r     s     &MBMG$$4K} % 
     
G
  YY|SXX^^D"})>$$TD[$F  
Gs    + B$2B)B1'BB$)r   NT)r   )TN)6r   r   r   astr^   r&  r   typeswarningscollections.abcr   r   r   ior   tokenizer   typingr   r	   r   r
   r   r   r   r   r   astroid._astr   r   astroid.constr   r   astroid.exceptionsr   r   r   r   r   r   r  filterwarningsSyntaxWarningr/   r;   rH   r=   r   r   r   r	  r  r"  r   r    r$   r"   <module>r7     s   
 # 
 	 	    : :  $ & I I 8 0 W W.
    H&A=Q<m
"-W\00 WtF.&3R FS"l! !r$   