
    ^hy                        % S r SSKrSSKJr  SSKJrJrJrJrJ	r	J
r
  \R                  S:  a  SSKJr  OSSKJr  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  SSKJrJrJrJr  \R@                  " \5        \RB                  r"\\#S'   \	" S5      r$\
\\4   r%\&r'\&r(\RR                  \RT                  \RV                  1r,\\#S'   \"RZ                  \"R\                  \"R^                  \"R`                  \"Rb                  \"Rd                  \"Rf                  \"Rh                  \"Rj                  \"Rl                  1
r7\\#S'   Sr8\\#S'   S\Rr                  \8'   SS1r:\\#S'   \Rv                  \Rx                  \Rz                  \R|                  \R~                  \R                  1rA\\#S'   \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  1rP\\#S'   \R                  \R                  1rQ\\#S'   \Q\R                  1-  rR\\#S'   \"R                  \"R                  \"R                  \"R                  \"R                  1rX\\#S'   \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  1r`\\#S'   \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  \"R                  1rp\\#S'   \"R                  \"R                  1rs\\#S'   1 Skrt\\#S '   \"R                  \"R                  \"R                  1rw\\#S!'   \R                  \R                  \R                  \R                  \R                  \R                  0r~\\#S"'   \" \~GR                  5       5      r\\#S#'   \" \~GR                  5       5      r\\#S$'   \\-  r\\#S%'   \\GR
                  \8\GR                  \GR                  \GR                  1-  r\\#S&'   S'r\" S(S)9 " S* S+\\$   5      5       rS,\S-\S.\S/\4S0 jrS|S1\&S2\S3\S/\4S4 jjrS5\\%   S/\\   4S6 jrS5\\%   S7\\\(      S/\4S8 jrS5\\%   S/\\(   4S9 jrS:\S;\%S/\\%   4S< jrS=\%S>\%S/S4S? jrS,\S/\%4S@ jrS5\%S/\\   4SA jrS5\%S/\4SB jrS5\S/\4SC jrS5\%S/\4SD jrS5\%S/\4SE jrS5\%S/\4SF jrS5\%S/\4SG jrS5\%S/\4SH jrS5\%S/\4SI jr\R                  \R                  44SJ\SK\SL\\   SM\\&\&4   S/\4
SN jjrS5\%S/\4SO jrS}S5\%SP\S/\4SQ jjrS5\%S/\4SR jrS5\%S/\4SS jrS,\ST\\(   S/\4SU jrS5\S/\4SV jrS5\S/\4SW jrS5\%S/\4SX jrS5\S/\4SY jrS5\S/\4SZ jrS5\S/\4S[ jrS5\%S/\4S\ jrS5\%S/\4S] jrS,\S/\4S^ jrS,\S/\4S_ jrS,\S/\4S` jrS,\S/\4Sa jrS,\S/\4Sb jrS,\S/\4Sc jrS,\S/\4Sd jrS,\S/\4Se jrSf\S/\4Sg jrS(Sh.Si\Sj\%Sk\S/S4Sl jjrS5\%S/\\%   4Sm jrS,\S/S4Sn jrSo\S/\\   4Sp jrSo\S/\\   4Sq jrSo\S/\\   4Sr jrSo\S/\\   4Ss jrS,\S/\St   4Su jrS,\S/\4Sv jrS5\%S/\\   4Sw jrS5\%S/\\   4Sx jrS,\S/\%4Sy jrS5\%Sz\&S/\4S{ jrg)~z>
blib2to3 Node/Leaf transformation-related utility functions.
    N)Iterator)FinalGenericLiteralOptionalTypeVarUnion)   
   )	TypeGuard)
mypyc_attr)	CACHE_DIR)Mode)get_string_prefixhas_triple_quotes)pygram)token)NLLeafNode	type_reprsymsT
WHITESPACE	STATEMENT   STANDALONE_COMMENTandorLOGIC_OPERATORSCOMPARATORSMATH_OPERATORSSTARSVARARGS_SPECIALSVARARGS_PARENTSUNPACKING_PARENTSTEST_DESCENDANTSTYPED_NAMES>   :=%=&=*=+=-=/=@=^=|=**=//=<<=>>=ASSIGNMENTSIMPLICIT_TUPLEBRACKETOPENING_BRACKETSCLOSING_BRACKETSBRACKETSALWAYS_NO_SPACE7   T)allow_interpreted_subclassesc                   H    \ rS rSrSrS\S\\   4S jrS\S\\   4S jr	Sr
g)	Visitor   zBBasic lib2to3 visitor that yields things of type `T` on `visit()`.nodereturnc              #   .  #    UR                   S:  a  [        R                  UR                      nO[        [	        UR                   5      5      n[        U SU 3S5      nU(       a  U" U5       Sh  vN   gU R                  U5       Sh  vN   g N N7f)aJ  Main method to visit `node` and its children.

It tries to find a `visit_*()` method for the given `node.type`, like
`visit_simple_stmt` for Node objects or `visit_INDENT` for Leaf objects.
If no dedicated `visit_*()` method is found, chooses `visit_default()`
instead.

Then yields objects of type `T` from the selected visitor.
   visit_N)typer   tok_namestrr   getattrvisit_default)selfrD   namevisitfs       E/home/james-whalen/.local/lib/python3.13/site-packages/black/nodes.pyvisitVisitor.visit   sy      99s?>>$)),Dy+,D
 v5d|##))$/// $/s$   A/B1B2BBBBc              #      #    [        U[        5      (       a-  UR                   H  nU R                  U5       Sh  vN   M     gg N
7f)zCDefault `visit_*()` implementation. Recurses to children of `node`.N)
isinstancer   childrenrR   )rN   rD   childs      rQ   rM   Visitor.visit_default   s:     dD!!::e,,, ' ",s   9AAA N)__name__
__module____qualname____firstlineno____doc__LNr   r   rR   rM   __static_attributes__rY       rQ   rB   rB      s3    L0" 0! 00-" -! -ra   rB   leafcomplex_subscriptmoderE   c                   SnSnSnU R                   nU R                  nU R                  nU[        ;   a  U$ U[        R
                  :X  a  U$ Uc   SU < 35       eU[        R                  :X  a?  UR                   [        R                  [        R                  [        R                  1;  a  U$ U[        R                  :X  a   UR                   [        R                  :X  a  U$ U R                  n	U	(       Gd  [        U5      n
U
(       a  U
R                   [        ;   a  U$ U[        R                  :X  aI  U
R                   [        R                  :X  a  U$ U
R                   [        R                   :w  a	  U(       d  U$ U$ U
R                   [        R"                  :X  a  U
R                  (       a  U
R                  R                   [        R$                  [        R&                  [        R(                  [        R*                  1;   a  U$ U
R                  R                   [        R,                  :X  a  U
R.                  $ GOU
R                   [        R0                  :X  aV  [3        U
5      [        R4                  :X  a9  [3        U
R                  5      [        R                  [        R6                  4;   a  U$ U
R                   [8        ;   a  [;        U
[<        [>        -  S9(       a  U$ GORU
R                   [        R                  :X  aU  U
R                  (       aC  U
R                  R                   [        R                  [        R                  1;   a  U(       a  U$ U$ OU
R                  (       a>  U
R                  R                   [        R@                  :X  a  U
R                   [B        ;   a  U$ U
R                   [        RD                  :X  a;  UR                  (       a*  UR                  R                   [        RF                  :X  a  U$ O6U	R                   [        ;   a  U$ U	R                   [        RH                  :X  a  U$ UR                   [        R(                  [        R$                  1;   a*  U	(       a  U	R                   [        R                   :w  a  U$  U$ UR                   [        R*                  :X  a)  U	(       a   U	R                   [        R                   :w  a  U$ U$ UR                   [        R,                  :X  a  U	(       d  U$ U[        R"                  :X  a  U	R                   [J        ;  a  U$  U$ U	R                   [        R"                  :X  a  U	R.                  $ U	R                   [        R                   :w  a  U$  U$ UR                   [J        ;   a;  U	(       d2  [        U5      n
U
(       a  U
R                   [        R                   :w  a  U$ U$ UR                   [        RL                  :X  a  U[        RN                  :X  d  U[        RP                  :X  a  U$ U	(       d-  U[        RR                  :X  d  U[        RT                  :X  a  U$  U$ U	R                   [        R                   :w  a  U$  U$ UR                   [        R&                  :X  a}  U[        R"                  :X  a  U$ U	(       d5  [        U5      n
U
(       a  U
R                   [        RN                  :X  a  U$  U$ U	R                   [        R"                  1[8        -  ;   a  U$  U$ UR                   [        RF                  :X  a  U$ UR                   [        RV                  :X  a\  U	(       a  U$ [        U5      n
U
(       a<  U
R                   [        RD                  :X  d  U
R                   [        RR                  :X  a  U$  U$ UR                   [        RX                  :X  a?  U[        RN                  :X  a  U$ U	(       a   U	R                   [        RN                  :X  a  U$ U$ UR                   [        R                  [        R                  1;   a  U	(       d@  UR                  c   S5       eUR                  R                   [        R                  :X  a  U$ U$ U[        RZ                  :X  d  U	R                   [        RZ                  :X  a  U$ U(       d  U$  U$ UR                   [        R\                  :X  a  U	(       a  U[        RR                  :X  a  U$ U$ UR                   [        R^                  :X  a)  U	(       a   U	R                   [        R`                  :X  a  U$ U$ UR                   [        R@                  [        R4                  1;   Ga  U	(       d  [        U5      n
U
(       a  U
R                   [        ;   a  U$ U
R                  nUc   eU
R                   [        R                  :X  a0  UR                   [        R                  [        R                  1;   a  U$ U
R                   [        R"                  :X  a   UR                   [        R&                  :X  a  U$ U$ U[        Rb                  [        Rd                  [        Rf                  1;   a  U$  U$ UR                   [        Rh                  :X  a  U[        RR                  :X  a)  U	(       a   U	R                   [        RR                  :X  a  U$ U$ U[        Rb                  :X  a/  US:X  a  U$ U	(       a   U	R                   [        RR                  :X  a  U$ U$ UR                   [        R                  :X  a  U$ UR                   [        Rj                  :X  a  U[        R0                  :X  a  U$ U$ )zReturn whitespace prefix if needed for the given `leaf`.

`complex_subscript` signals whether the given leaf is part of a subscription
which has non-trivial arguments, like arithmetic expressions or function calls.
  z  z/INTERNAL ERROR: hand-made leaf without parent: )withinzsubscripts are always parentedimport)6rI   parentvaluer>   r   COMMENTCOLONr   	subscriptsubscriptlistsliceopLBRACEfstring_replacement_fieldprev_siblingpreceding_leafr;   COMMAEQUALarglistargument
parametersvarargslisttypedargslistprefixSTARparent_type	star_expr
tname_starr$   	is_varargr%   r&   factorr"   AT	decoratorBANGr(   trailerLPARRPARDOTLSQBdotted_nameclassdef
COLONEQUALatomdictsetmaker
DOUBLESTARNAMENUMBERSTRINGimport_fromexcept_clause)rb   rc   rd   NOSPACEDOUBLESPACEtpvprevprevpprevp_parents               rQ   
whitespacer      sK    BE"K		AA

AO	EMM=TKD8TT=EKKAFF+ 
 	ELLQVVt'E'EE	Dq!

&66IzzU[[(	u{{*3D	L::$||<<$$LLMMOO$$	)  I\\&&$*<*<< !<<' JJ%**$E"dnn4ELL)d.@.@$//-RR IZZ++9J'JK	 L ZZ5;;&|| 1 1dnndll5S S 1u9r9 LL!!T[[0

n,IZZ588#QXX]]dnn5TI	&	&		ejj	 	vv$//4<<00tyyEKK/I 0\ LW 
4##	#DII,IP LM 
4%%	%Iyy+	 ,@ L{ YY%++% ;;YY%++%I &p Lk 
;	"1%EEJJ%++5	` L] 
4<<	

?a5::oIEII~ejj	 "1P LK YY%++%I &J LE 
4==	 I"1%EEJJ%**4	 5v Lq YY5;;-*:::I ;p Lk 
4>>	!		
4##	#Iq!

ehh.%**		2II 3JX LS 
4==	 

?IDII+IH LE 
DNNDLL1	188'I)II'xx}} 2 22I%"""dii53C3C&CL"I #l Lg 
499	ANI` L] 
4$$	$DII!1!11IV LS 
DKK0	0"1%EEJJ*::	 <<L+++zzU[[(\->->C . 	u{{*|/@/@DMM/Q	2 L- 5::u||U\\::I ;, L' 
4##	#		>		UYY.	  L %**_H}		UYY.	 L 
4<<			
4%%	%

?ILra   nl_count	form_feed
empty_linec                 2    U(       a  X S-
  -  S-   U-   $ X -  $ )z$Generate a normalized prefix string.   rY   )r   r   r   s      rQ   make_simple_prefixr     s%    l+t3j@@  ra   rD   c                     U (       a\  U R                   nU(       a4  [        U[        5      (       a  U$  [        UR	                  5       5      S   $ U R                  n U (       a  M\  g! [
         a     gf = f)z3Return the first leaf that precedes `node`, if any.N)rs   rU   r   listleaves
IndexErrorrj   )rD   ress     rQ   rt   rt     sk    
#t$$
CJJL)"--
 {{ $ 	  s   A% %
A21A2tokensc                     U(       d  gUS   c  U SL $ U (       d  gU R                   US   :w  a  g[        U R                  USS 5      $ )a/  Return if the `node` and its previous siblings match types against the provided
list of tokens; the provided `node`has its type matched against the last element in
the list.  `None` can be used as the first element to declare that the start of the
list is anchored at the start of its parent's children.Tr   NF)rI   prev_siblings_arers   )rD   r   s     rQ   r   r     sP    
 bzt|yyF2JT..s<<ra   c                 P    U b  U R                   c  gU R                   R                  $ )zh
Returns:
    @node.parent.type, if @node is not None and has a parent.
        OR
    None, otherwise.
N)rj   rI   rD   s    rQ   r~   r~     s%     |t{{*;;ra   ancestor
descendantc                     UnU(       a5  UR                   U :w  a%  UR                   nU(       a  UR                   U :w  a  M%  U$ )z:Return the child of `ancestor` that contains `descendant`.)rj   )r   r   rD   s      rQ   child_towardsr     s3    #D
4;;(*{{ 4;;(*Kra   	old_child	new_childc                 v    U R                   nU(       d  gU R                  5       nUb  UR                  X15        gg)z
Side Effects:
    * If @old_child.parent is set, replace @old_child with @new_child in
    @old_child's underlying Node structure.
        OR
    * Otherwise, this function does nothing.
N)rj   removeinsert_child)r   r   rj   	child_idxs       rQ   replace_childr     s<     F  "II1 ra   c                 H   U R                   nU nU(       a  UR                  nUc   U$ UR                  S   R                   U:w  a   U$ UR                  [        R
                  :X  a   U$ UR                  b!  UR                  R                  [        ;   a   U$ UnU(       a  M  U$ )zReturn `leaf` or one of its ancestors that is the topmost container of it.

By "container" we mean a node where `leaf` is the very first child.
r   )r|   rj   rV   rI   r   
file_inputrs   r=   )rb   same_prefix	containerrj   s       rQ   container_ofr     s    
 ++KI
!!>  ??1$$3  ;;$//) 	 *v/B/B/G/G8/S  	 ) ra   c                     [        U [        5      (       a  U $ U R                  (       a  [        U R                  S   5      $ g)z(Returns the first leaf of the node tree.r   N)rU   r   rV   first_leaf_ofr   s    rQ   r   r     s2    $}}T]]1-..ra   c                     U R                   [        R                  [        R                  [        R                  [        R
                  1;   $ )z?Whether node is an arithmetic or a binary arithmetic expression)rI   r   
arith_expr
shift_exprxor_exprand_exprr   s    rQ   is_arith_liker     s4    99	  ra   c                 @   [        U [        5      (       aT  U R                  [        R                  :w  a  g[        U R                  5      n[        U5      R                  S5      (       a  gU R                  (       a  U R                  R                  [        R                  :X  ai  U R                  R                  (       dN  U R                  R                  (       a3  U R                  R                  R                  [        R                  :X  a  g[        U R                  S [        R                  [        R                   [        R                  /5      (       a  g[        U R                  [        R"                  [        R$                  [        R                  /5      (       a  gg)NFbBfFT)rU   r   rI   r   r   r   rk   setintersectionrj   r   simple_stmtrs   r   r   NEWLINEINDENTry   rm   )rD   r|   s     rQ   is_docstringr   $  s   $99$"4::.v;##F++ 	KK 0 00((KKKK##t6dEMM5<<9I9IJ   tTEUEU&VWW ra   c                 >   U R                   [        R                  :H  =(       az    [        U R                  5      S:H  =(       a[    U R                  S   R                   [
        R                  :H  =(       a*    U R                  S   R                   [
        R                  :H  $ )z+Return True if `node` holds an empty tuple.   r   r   )rI   r   r   lenrV   r   r   r   r   s    rQ   is_empty_tupler   D  sq     			TYY 	0!#	0MM!!!UZZ/	0 MM!!!UZZ/	ra   c                    U R                   [        R                  :X  av  [        U 5      nUb  UR                   [        R                  :w  a  g[        UR                  5      S:H  =(       a*    UR                  S   R                   [        R                  :H  $ U R                   [        ;   =(       aI    [        U R                  5      S:H  =(       a*    U R                  S   R                   [        R                  :H  $ )zMReturn True if `node` holds a tuple with one element, with or without parens.Fr   r   )
rI   r   r   unwrap_singleton_parenthesistestlist_gexpr   rV   r   ru   r9   rD   gexps     rQ   is_one_tupler   N  s    yyDII+D1<499(:(::4==!Q&O4==+;+@+@EKK+OO 			^# 	1!#	1MM!!!U[[0ra   c                     U R                   [        R                  :w  a  g[        U 5      nUb  UR                   [        R                  :w  a  gg)z$Return True if `node` holds a tuple.FT)rI   r   r   r   r   r   s     rQ   is_tupler   ^  s;    yyDII'-D|tyyD$6$66ra   c                     U R                   [        R                  :w  a  g[        U 5      nUb  UR                   [        R                  :w  a  g[        S UR                   5       5      $ )zDReturn True if `node` holds a tuple that contains a walrus operator.Fc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fN)rI   r   namedexpr_test.0rW   s     rQ   	<genexpr>-is_tuple_containing_walrus.<locals>.<genexpr>q  s     LmUzzT000m   )+rI   r   r   r   r   anyrV   r   s     rQ   is_tuple_containing_walrusr   i  sM    yyDII'-D|tyyD$6$66LdmmLLLra   c                     U R                   [        R                  :w  a  g[        U 5      nUb  UR                   [        R                  :w  a  g[        S UR                   5       5      $ )zBReturn True if `node` holds a tuple that contains a star operator.Fc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr   )rI   r   r   r   s     rQ   r   +is_tuple_containing_star.<locals>.<genexpr>|  s     GzzT^^+r   r   r   s     rQ   is_tuple_containing_starr   t  sM    yyDII'-D|tyyD$6$66GGGGra   c                     U R                   [        R                  :w  a  g[        U 5      nUb  UR                   [        R                  :w  a  g[        S UR                   5       5      $ )z(Return True if `node` holds a generator.Fc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr   )rI   r   old_comp_forr   s     rQ   r   is_generator.<locals>.<genexpr>  s     JM5zzT...Mr   r   r   s     rQ   is_generatorr     sM    yyDII'-D|tyyD$6$66JDMMJJJra   openingclosingr   bracketsc                    U R                   UR                   4U:w  a  gUR                  S-   n[        U5       H  u  pVX`L d  M    O   [        S5      eSnUS-  nX%S  H  nXaL a    US:  $ UR                  nX:X  d  M   UR                   [        R
                  :X  d  M@  US-  nUR                  (       d  MX  UR                  R                   [        R                  [        R                  1;   d  M  US-  n  US:  $    US:  $ )zIReturn True if content between `opening` and `closing` is a one-sequence.Fr   z#Opening paren not found in `leaves`r   Nr   )
rI   bracket_depth	enumerateLookupErrorr   ru   rj   r   rw   r{   )	r   r   r   r   depth_opening_indexrb   commasr   s	            rQ   is_one_sequence_betweenr     s    	gll#x/!!A%E )& 1? !2
 ?@@FaN'? A: **!dii5;;&>aKF{{{t{{//""4   !A: ( A:ra   c                 h    [        U 5      nUSL=(       a    UR                  [        R                  :H  $ )z7Return True iff `node` is of the shape ( test := test )N)r   rI   r   r   )rD   inners     rQ   is_walrus_assignmentr     s+    (.EBt/B/B!BBra   lastc                 j   U R                   [        R                  :H  =(       Ga    [        U R                  5      S:H  =(       a[    U R                  S   R                   [
        R                  :H  =(       a*    U R                  S   R                   [
        R                  :H  =(       Gd    U=(       az    [        U R                  5      S:H  =(       a[    U R                  S   R                   [
        R                  :H  =(       a*    U R                  S   R                   [
        R                  :H  =(       d    U=(       az    [        U R                  5      S:H  =(       a[    U R                  S   R                   [
        R                  :H  =(       a*    U R                  S   R                   [
        R                  :H  $ )z?Return True iff `node` is a trailer valid in a simple decoratorr   r   r   r
   )
rI   r   r   r   rV   r   r   r   r   r   )rD   r  s     rQ   is_simple_decorator_trailerr    s;   99$  !# 4a %%24a %%3	
 	
  4DMM"a'4a %%34 a %%3	
  4DMM"a'4a %%34 a %%3'ra   c                    U R                   [        R                  :X  a  gU R                   [        R                  :X  a  U R
                  (       a  U R
                  S   R                   [        R                  :H  =(       ac    [        [        [        U R
                  SS 5      5      =(       a6    [        U R
                  5      S:  =(       d    [        U R
                  S   SS9$ g)aH  Return True iff `node` could be a 'dotted name' decorator

This function takes the node of the 'namedexpr_test' of the new decorator
grammar and test if it would be valid under the old decorator grammar.

The old grammar was: decorator: @ dotted_name [arguments] NEWLINE
The new grammar is : decorator: @ namedexpr_test NEWLINE
Tr   r   r   r   )r  F)
rI   r   r   r   powerrV   allmapr  r   r   s    rQ   is_simple_decorator_expressionr    s     yyEJJyyDJJ==a %%3 7q9LMN &* Q24==3D4P ra   c                    U R                   [        R                  :X  a  g[        U 5      (       a  U R                  S:X  a  gU R                   [        R
                  :w  a  g[        U R                  5      S:w  a  gU R                  u  pnUR                   [        R                  :X  a)  UR                   [        R                  :X  a  [        U5      $ g)zAReturn True if `node` holds a `yield` or `yield from` expression.TyieldFr
   )rI   r   
yield_expris_name_tokenrk   r   r   rV   r   r   r   is_yield)rD   lparexprrpars       rQ   r  r    s    yyDOO#TtzzW4yyDII
4==Q}}DyyEJJ499

#:~ra   rh   c                     U R                   [        ;  d  U R                  (       d  gU R                  nUR                   [        R                  :X  a  UR                  (       d  gUR                  nUR                   U;   $ )a2  Return True if `leaf` is a star or double star in a vararg or kwarg.

If `within` includes VARARGS_PARENTS, this applies to function signatures.
If `within` includes UNPACKING_PARENTS, it applies to right hand-side
extended iterable unpacking (PEP 3132) and additional unpacking
generalizations (PEP 448).
F)rI   r$   rj   r   r   )rb   rh   r   s      rQ   r   r     sW     yy((Avv xxHH66Vra   c                 <    U R                   [        R                  :H  $ )z&Return True if the node is an f-string)rI   r   fstringr   s    rQ   
is_fstringr    s    99$$ra   c                     [        U 5      [        U R                  5      S n[        [        R
                  XR                  S9nU R                  5       =(       d    SUl        U$ )z/Converts an fstring node back to a string node.N)r|   r   )rK   r   r|   r   r   r   
get_linenolineno)rD   string_without_prefixstring_leafs      rQ   fstring_to_stringr    sL    Ic$++&6&89u||%:;;OK*/aKra   c                     [        U [        5      (       a  [        U 5      (       a  [        U 5      nO[        U [        5      (       a  U nOg[        UR                  5      =(       a    SUR                  ;   $ )zKReturn True if `leaf` is a multiline string that actually spans many lines.F
)rU   r   r  r  r   r   rk   )rD   rb   s     rQ   is_multiline_stringr     sU    $*T"2"2 &	D$		TZZ(?TTZZ-??ra   c                     U R                   [        R                  [        R                  1;   d   eU R                  c   eU R                  R                   [        R
                  [        R                  1;   $ r   )rI   r   suiter   rj   funcdefr   r   s    rQ   is_parent_function_or_classr!  ,  sU    99T%5%56666;;""";;dmm<<<ra   c                 z    U R                   [        R                  [        R                  [        R                  1;   $ r   )rI   r   r   r   async_funcdefr   s    rQ   is_function_or_classr$  3  s&    99t}}d6H6HIIIra   c                 >   U R                   b  [        U 5      (       d  gU R                  R                  5       (       a  g[	        U R
                  5      S:w  d  U R
                  S   R                  [        R                  :w  dV  U R
                  S   R                  [        R                  :w  d+  U R
                  S   R                  [        R                  :w  a  gU R
                  S   R                  R                  5       (       a  g[        U R
                  S   5      $ )z2Return True if `node` is a suite with a stub body.F   r   r   r
   r   )rj   r!  r|   stripr   rV   rI   r   r   r   DEDENTis_stub_bodyr   s    rQ   is_stub_suiter*  7  s    {{'B4'H'H {{ 	DMMa==  EMM1==  ELL0==  ELL0}}Q$$&&a())ra   c                    [        U [        5      (       a  U R                  [        R                  :w  a  g[        U R                  5      S:w  a  gU R                  S   nUR                  R                  5       (       + =(       a_    UR                  [        R                  :H  =(       a;    [        UR                  5      S:H  =(       a    [        S UR                   5       5      $ )zCReturn True if `node` is a simple statement containing an ellipsis.Fr   r   r
   c              3   Z   #    U  H!  o[        [        R                  S 5      :H  v   M#     g7f).N)r   r   r   )r   rb   s     rQ   r   is_stub_body.<locals>.<genexpr>[  s     HUYY,,r   )rU   r   rI   r   r   r   rV   r|   r'  r   r  )rD   rW   s     rQ   r)  r)  N  s    dD!!TYY$2B2B%B
4==QMM!ELL   	IJJ$))#	I1$	I HHH	ra   c                    [        U [        5      (       d  U R                  [        R                  :w  a  gU R
                  S   U R
                  S   p![        U[        5      =(       a    UR                  [        R                  :H  =(       a`    UR                  S:H  =(       aJ    [        U[        5      =(       a3    UR                  [        R                  :H  =(       a    UR                  S:H  $ )zyGiven a `LN`, determines whether it's an atom `node` with invisible
parens. Useful in dedupe-ing and normalizing parens.
Fr   r   rf   )
rU   r   rI   r   r   rV   r   r   rk   r   )rD   firstr  s      rQ   is_atom_with_invisible_parensr1  _  s     $dii!7--"DMM"$545$ 	JJ%**$	KK2	 tT"	 II#		
 JJ"ra   c                 <    [        U 5      =(       d    [        U 5      $ r   )is_empty_lparis_empty_rparrb   s    rQ   is_empty_parr6  q  s    5-"55ra   c                 h    U R                   [        R                  :H  =(       a    U R                  S:H  $ Nrf   )rI   r   r   rk   r5  s    rQ   r3  r3  u  #    99

"7tzzR'77ra   c                 h    U R                   [        R                  :H  =(       a    U R                  S:H  $ r8  )rI   r   r   rk   r5  s    rQ   r4  r4  y  r9  ra   c                 f   U R                   nU R                  nU R                  n[        U[        R
                  :H  =(       ak    US:H  =(       a&    U=(       a    UR                  [        R                  :H  =(       d2    US:H  =(       a&    U=(       a    UR                  [        R                  :H  5      $ )z9Return True if the given leaf starts an import statement.ri   from)	rj   rI   rk   boolr   r   r   import_namer   )rb   r   r   r   s       rQ   	is_importr?  }  s    A		A

A	UZZ 	
(]?q?QVVt/?/?%? BV@@aff0@0@&@	 ra   c                    [        U R                  [        R                  :H  =(       aP    U R                  S:H  =(       a:    U R
                  =(       a'    U R
                  R                  [        R                  :H  5      =(       dg    [        U R                  [        R                  :H  =(       a:    U R                  =(       a'    U R                  R                  [        R                  :H  5      $ )zDReturn True if the given leaf starts a with or async with statement.with)
r=  rI   r   r   rk   rj   r   	with_stmtASYNCnext_siblingr5  s    rQ   is_with_or_async_with_stmtrE    s    		UZZ 	/JJ& 	/KK	/ KK.	 	
 
		U[[  	5	5""dnn4
	ra   c                     [        U R                  [        R                  :H  =(       aJ    U R                  =(       a7    U R                  R                  [
        R                  [
        R                  1;   5      $ )zReturn True if the given leaf starts an async def/for/with statement.

Note that `async def` can be either an `async_stmt` or `async_funcdef`,
the latter is used when it has decorators.
)r=  rI   r   rC  rj   r   
async_stmtr#  r5  s    rQ   is_async_stmt_or_funcdefrH    sU     		U[[  	FKK	FKK$2D2D EE ra   c                     U R                   nU R                  nU[        R                  [        1;   =(       a    UR                  S5      $ )a6  Return True if the given leaf is a type comment. This function should only
be used for general type comments (excluding ignore annotations, which should
use `is_type_ignore_comment`). Note that general type comments are no longer
used in modern version of Python, this function may be deprecated in the future.z# type:)rI   rk   r   rl   r   
startswithrb   r   r   s      rQ   is_type_commentrL    s9    
 			A

A 233OY8OOra   c                     U R                   nU R                  nU[        R                  [        1;   =(       a    [        U5      $ )zGReturn True if the given leaf is a type comment with ignore annotation.)rI   rk   r   rl   r   is_type_ignore_comment_stringrK  s      rQ   is_type_ignore_commentrO    s5    		A

A 233X8UVW8XXra   rk   c                 $    U R                  S5      $ )zOReturn True if the given string match with type comment with
ignore annotation.z# type: ignore)rJ  )rk   s    rQ   rN  rN    s     ,--ra   )visiblerj   rW   rQ  c                N   [        [        R                  U(       a  SOS5      n[        [        R                  U(       a  SOS5      nUR                  nSUl        UR                  5       =(       d    Sn[        [        R                  X1U/5      nXWl        U R                  Xg5        g)zWrap `child` in parentheses.

This replaces `child` with an atom holding the parentheses and the old
child.  That requires moving the prefix.

If `visible` is False, the leaves will be valueless (and thus invisible).
(rf   )r   N)
r   r   r   r   r|   r   r   r   r   r   )rj   rW   rQ  r  r  r|   indexr   s           rQ   wrap_in_parenthesesrV    su     

7C3D

7C3D\\FELLLNaETYYd 34I
)ra   c                     [        U R                  5      S:w  a  gU R                  u  pnUR                  [        R                  :X  a  UR                  [        R
                  :X  d  gU$ )zmReturns `wrapped` if `node` is of the shape ( wrapped ).

Parenthesis can be optional. Returns None otherwiser
   N)r   rV   rI   r   r   r   )rD   r  wrappedr  s       rQ   r   r     sM     4==Q--D4II#		UZZ(?Nra   c                     U R                   [        R                  :X  a  SU l        gU R                   [        R                  :X  a  SU l        gg)zMake sure parentheses are visible.

They could be invisible as part of some statements (see
:func:`normalize_invisible_parens` and :func:`visit_import_from`).
rS  rT  N)rI   r   r   rk   r   r5  s    rQ   ensure_visiblerZ    s7     yyEJJ
	ejj	 
 
!ra   nlc                 <    U R                   [        R                  :H  $ r   )rI   r   r   r[  s    rQ   r  r        77ejj  ra   c                 <    U R                   [        R                  :H  $ r   )rI   r   r   r]  s    rQ   is_lpar_tokenr`    r^  ra   c                 <    U R                   [        R                  :H  $ r   )rI   r   r   r]  s    rQ   is_rpar_tokenrb    r^  ra   c                 <    U R                   [        R                  :H  $ r   )rI   r   r   r]  s    rQ   is_number_tokenrd    s    77ell""ra   )rE   paramNc                 ,   U R                   nUb  UR                  (       a)  UR                  R                  [        R                  :X  a  gUR                   (       a)  UR                   R                  [
        R                  :X  a  gUR                   nUb  M  g)z<Returns the type of annotation this leaf is part of, if any.NrE   re  )rj   rs   rI   r   RARROWr   tname)rb   r   s     rQ   get_annotation_typeri    si    {{H

  X%:%:%?%?5<<%O??x33tzzA?? 
 ra   c                 :    U R                   c   e[        U 5      SL$ )z7Returns whether this leaf is part of a type annotation.N)rj   ri  r5  s    rQ   is_part_of_annotationrk    s"    ;;"""t$D00ra   c                     [        U [        5      (       a  U $ U R                  (       d  g[        U R                  S   5      $ )z,Returns the first leaf of the ancestor node.Nr   )rU   r   rV   
first_leafr   s    rQ   rm  rm    s2    $]]$--*++ra   c                     [        U [        5      (       a  U $ U R                  (       d  g[        U R                  S   5      $ )z+Returns the last leaf of the ancestor node.Nr   )rU   r   rV   	last_leafr   s    rQ   ro  ro    s2    $]]r*++ra   c                 B   U nUR                   (       a  UR                   R                  (       ap  XR                   R                  S   L aU  UR                   nUR                   (       a8  UR                   R                  (       a  XR                   R                  S   L a  MU  U$ )zGReturns the furthest ancestor that has this leaf node as the last leaf.r   )rj   rV   )rb   rD   s     rQ    furthest_ancestor_with_last_leafrq    sg    D
++$++..4;;;O;OPR;S3S{{ ++$++..4;;;O;OPR;S3SKra   rI   c                     U R                   nUb"  UR                  U:X  a  gUR                   nUb  M"  U R                  nUb"  UR                  U:X  a  gUR                  nUb  M"  g)NTF)rs   rI   rD  )rD   rI   siblings      rQ   has_sibling_with_typert  '  so    G

<<4&& 
 G

<<4&& 

 ra   )r  )F)r^   syscollections.abcr   typingr   r   r   r   r   r	   version_infor   typing_extensionsmypy_extensionsr   black.cacher   
black.moder   black.stringsr   r   blib2to3r   blib2to3.pgen2r   blib2to3.pytreer   r   r   r   
initializepython_symbolsr   __annotations__r   r_   intLeafIDNodeTyper(  r   r   r   if_stmt
while_stmtfor_stmttry_stmtr   rB  r   r   
match_stmt
case_blockr   r   rJ   r    LESSGREATEREQEQUALNOTEQUAL	LESSEQUALGREATEREQUALr!   VBAR
CIRCUMFLEXAMPER	LEFTSHIFT
RIGHTSHIFTPLUSMINUSr}   SLASHDOUBLESLASHPERCENTr   TILDEr   r"   r#   r$   rw   rx   r   r{   rz   r%   r   r   	listmakerr   testlist_star_exprsubject_exprpatternr&   testlambdefor_testand_testnot_test
comparisonr   r  r   r   r   r   termr  r   r'   rh  r   r(   r8   testlistexprlistr9   r   r   r   RSQBrq   RBRACEr:   r   keysr;   valuesr<   r=   ru   FSTRING_MIDDLEFSTRING_ENDr   r>   rg  rB   r=  rK   r   r   rt   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   tupler   r   r  r  r  r   r  r  r  r!  r$  r*  r)  r1  r6  r3  r4  r?  rE  rH  rL  rO  rN  rV  r   rZ  r  r`  rb  rd  ri  rk  rm  ro  rq  rt  rY   ra   rQ   <module>r     s"	    $ D Dw + & !  >    5 5   ) ##e # CL
4:	 \\5<<?
E ?LLOOMMMMNNLLMMOOOO	5    E %9! " &	JJ	MM	MM	NN	OO	U  
JJ		KK	OO		JJ	KK	JJ	KK		MM	HH	KK	   

E,,-u -5;;-/ % /LLMMLL  	IINNLL 5  	IILLLLMMMMOONNIIMMMMOOOOLLIIJJ! % $ jj$//2U 2U $ (?(?O O	JJ

	JJ

	LL%,, 
 glln- % -gnn./ % /"%55% 5)	KK			JJ-   
 .-gaj - /-DmT m mT mc m`! ! !3 !RU !" (4. $=HRL =$x7I2J =t = 
hrl 
x'9 
D b Xb\ 2R 2B 24 2"t  2 x~  t r d @  r d  2 $ MR MD MH2 H$ HKr Kd K "'UZZ 8	""" J" CHo	"
 
"JCr Cd Cb   4  02 $ *D #h- D .%T %d %
D T 	@b 	@T 	@=d =t =Jt J J* * *.r d " t $6t 6 68 8 88 8 8D T T d 
4 
D 
P$ P4 PY Y$ Y. . . EI * *R *T *T *$r hrl 	 	$ 	!b !Yt_ !!b !Yt_ !!b !Yt_ !# #y #	d 	w/F'G 	1 1 1,R ,HTN ,,B ,8D> ,4 B  # $ ra   