
    ^h0                        % S r SSKJrJr  SSKJrJr  SSKJrJ	r	J
r
  SSKJrJrJrJrJrJrJrJrJrJr  SSKJr  SSKJrJr  \
\\4   r\r\r\r\r Sr!\\"S	'   S
r#\\"S'   Sr$\\"S'   Sr%\\"S'   Sr&\\"S'   Sr'\\"S'   \RP                  S\RR                  S\RT                  S\RV                  S\RX                  S\RZ                  S\R\                  S\R^                  S\R`                  S\Rb                  S\Rd                  S\Rf                  S\Rh                  S\Rj                  S0r6\\"S'   Sr7\\"S'    " S S \85      r9\ " S! S"5      5       r:S#\S$\ 4S% jr;S-S#\S'\	\   S$\ 4S( jjr<S)\S$\ 4S* jr=S+\\   S$\>\   4S, jr?g&).z,Builds on top of nodes.py to track brackets.    )IterableSequence)	dataclassfield)FinalOptionalUnion)
BRACKETCLOSING_BRACKETSCOMPARATORSLOGIC_OPERATORSMATH_OPERATORSOPENING_BRACKETSUNPACKING_PARENTSVARARGS_PARENTS	is_varargsyms)token)LeafNode   COMPREHENSION_PRIORITY   COMMA_PRIORITY   TERNARY_PRIORITY   LOGIC_PRIORITY   STRING_PRIORITY
   COMPARATOR_PRIORITY	                        MATH_PRIORITIES   DOT_PRIORITYc                       \ rS rSrSrSrg)BracketMatchError7   zLRaised when an opening bracket is unable to be matched to a closing bracket. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r1       H/home/james-whalen/.local/lib/python3.13/site-packages/black/brackets.pyr/   r/   7   s    Vr8   r/   c                      \ rS rSr% SrSr\\S'   \" \	S9r
\	\\\4   \4   \S'   \" \	S9r\	\\4   \S'   Sr\\   \S	'   \" \S9r\\   \S
'   \" \S9r\\   \S'   \" \S9r\\   \S'   S\SS4S jrS\4S jrS\4S jrSS\\   S\4S jjrSS\S\4S jjrS\S\4S jrS\S\4S jr S\S\4S jr!S\S\4S jr"S\\   4S jr#Sr$g)BracketTracker;   z"Keeps track of brackets on a line.r   depth)default_factorybracket_match
delimitersNprevious_for_loop_depths_lambda_argument_depths	invisibleleafreturnc                    UR                   [        R                  :X  a  gU R                  S:X  a;  UR                   [        ;   a'  U R                  UR                   4U R
                  ;  a  gU R                  U5        U R                  U5        UR                   [        ;   ay  U =R                  S-  sl         U R
                  R                  U R                  UR                   45      nX!l        UR                  (       d  U R                  R                  U5        U R                  Ul        U R                  S:X  at  [!        XR"                  5      nU(       a/  U R"                  b"  X@R$                  ['        U R"                  5      '   O)[)        U5      nU(       a  X@R$                  ['        U5      '   UR                   [*        ;   al  XR
                  U R                  [,        UR                      4'   U =R                  S-  sl        UR                  (       d  U R                  R                  U5        Xl        U R/                  U5        U R1                  U5        g! [         a  n[        SU 35      UeSnAff = f)a;  Mark `leaf` with bracket-related metadata. Keep track of delimiters.

All leaves receive an int `bracket_depth` field that stores how deep
within brackets a given leaf is. 0 means there are no enclosing brackets
that started on this line.

If a leaf is itself a closing bracket and there is a matching opening
bracket earlier, it receives an `opening_bracket` field with which it forms a
pair. This is a one-directional link to avoid reference cycles. Closing
bracket without opening happens on lines continued from previous
breaks, e.g. `) -> "ReturnType":` as part of a funcdef where we place
the return type annotation on its own line of the previous closing RPAR.

If a leaf is a delimiter (a token on which Black can split the line if
needed) and it's on depth 0, its `id()` is stored in the tracker's
`delimiters` field.
Nr   r,   zDUnable to match a closing bracket to the following opening bracket: )typer   COMMENTr=   r   r?   'maybe_decrement_after_for_loop_variable&maybe_decrement_after_lambda_argumentspopKeyErrorr/   opening_bracketvaluerD   appendbracket_depthis_split_before_delimiterrA   r@   idis_split_after_delimiterr   r
    maybe_increment_lambda_arguments!maybe_increment_for_loop_variable)selfrE   rN   edelims        r9   markBracketTracker.markG   s   $ 99% JJ!O		--TYY't/A/AA44T:33D999((JJ!OJ"&"4"4"8"8$**dii9P"Q $3 ::%%d+!ZZ::?-dMMBE25:4== 120605OOBtH-99((AEtzz7499+==>JJ!OJ::%%d+--d3..t41  '!!%( s   71I 
I6"I11I6c                 R    [        U R                  =(       d    U R                  5      $ )zReturn True if there is an open for or lambda expression on the line.

See maybe_increment_for_loop_variable and maybe_increment_lambda_arguments
for details.)boolrB   rC   rW   s    r9   any_open_for_or_lambda%BracketTracker.any_open_for_or_lambda   s     
 D))IT-I-IJJr8   c                 ,    [        U R                  5      $ )zBReturn True if there is an yet unmatched open bracket on the line.)r]   r?   r^   s    r9   any_open_brackets BracketTracker.any_open_brackets   s    D&&''r8   excludec                 ^   ^ [        U4S jU R                  R                  5        5       5      $ )zReturn the highest priority of a delimiter found on the line.

Values are consistent with what `is_split_*_delimiter()` return.
Raises ValueError on no delimiters.
c              3   <   >#    U  H  u  pUT;  d  M  Uv   M     g 7fNr1   ).0kvrd   s      r9   	<genexpr>8BracketTracker.max_delimiter_priority.<locals>.<genexpr>   s     M!8AW<L11!8s   	)maxr@   items)rW   rd   s    `r9   max_delimiter_priority%BracketTracker.max_delimiter_priority   s#     M!6!6!8MMMr8   priorityc                    ^ U R                   (       d  gT=(       d    U R                  5       m[        U4S jU R                   R                  5        5       5      $ )z~Return the number of delimiters with the given `priority`.

If no `priority` is passed, defaults to max priority on the line.
r   c              3   6   >#    U  H  oT:X  d  M
  S v   M     g7f)r,   Nr1   )rh   prq   s     r9   rk   ?BracketTracker.delimiter_count_with_priority.<locals>.<genexpr>   s     H6x-116s   		)r@   ro   sumvalues)rW   rq   s    `r9   delimiter_count_with_priority,BracketTracker.delimiter_count_with_priority   s@    
 <t::<Hdoo446HHHr8   c                     UR                   [        R                  :X  aK  UR                  S:X  a;  U =R                  S-  sl        U R
                  R                  U R                  5        gg)zIn a for loop, or comprehension, the variables are often unpacks.

To avoid splitting on the comma in this situation, increase the depth of
tokens between `for` and `in`.
forr,   TF)rH   r   NAMErO   r=   rB   rP   rW   rE   s     r9   rV   0BracketTracker.maybe_increment_for_loop_variable   sJ     99

"tzzU':JJ!OJ!!((4r8   c                    U R                   (       a{  U R                   S   U R                  :X  a^  UR                  [        R                  :X  a@  UR
                  S:X  a0  U =R                  S-  sl        U R                   R                  5         gg)z>See `maybe_increment_for_loop_variable` above for explanation.inr,   TF)rB   r=   rH   r   r|   rO   rL   r}   s     r9   rJ   6BracketTracker.maybe_decrement_after_for_loop_variable   se     !!%%b)TZZ7		UZZ'

d"JJ!OJ!!%%'r8   c                     UR                   [        R                  :X  aK  UR                  S:X  a;  U =R                  S-  sl        U R
                  R                  U R                  5        gg)zIn a lambda expression, there might be more than one argument.

To avoid splitting on the comma in this situation, increase the depth of
tokens between `lambda` and `:`.
lambdar,   TF)rH   r   r|   rO   r=   rC   rP   r}   s     r9   rU   /BracketTracker.maybe_increment_lambda_arguments   sJ     99

"tzzX'=JJ!OJ((//

;r8   c                     U R                   (       ak  U R                   S   U R                  :X  aN  UR                  [        R                  :X  a0  U =R                  S-  sl        U R                   R                  5         gg)z=See `maybe_increment_lambda_arguments` above for explanation.r   r,   TF)rC   r=   rH   r   COLONrL   r}   s     r9   rK   5BracketTracker.maybe_decrement_after_lambda_arguments   sY     ((,,R0DJJ>		U[[(JJ!OJ((,,.r8   c                 r    U R                   R                  U R                  S-
  [        R                  45      $ )z7Return the most recent opening square bracket (if any).r,   )r?   getr=   r   RSQBr^   s    r9   get_open_lsqbBracketTracker.get_open_lsqb   s*    !!%%tzzA~uzz&BCCr8   )rA   )r1   )r   )%r2   r3   r4   r5   r6   r=   int__annotations__r   dictr?   tupleDepthNodeTyper   r@   LeafIDPriorityrA   r   listrB   rC   rD   rZ   r]   r_   rb   r   ro   rx   rV   rJ   rU   rK   r   r7   r1   r8   r9   r;   r;   ;   sO   ,E3N8=d8SM4eXo.45S).t)DJVX%&D#Hhtn#"'"=d3i=).t)DT#YD!$7ItDz7:5 :5$ :5xK K(4 (Nhv.> N N	Ih 	Is 	Id t D T T d 4 D Dx~ Dr8   r;   rE   rF   c                 L    U R                   [        R                  :X  a  [        $ g)zReturn the priority of the `leaf` delimiter, given a line break after it.

The delimiter priorities returned here are from those delimiters that would
cause a line break after themselves.

Higher numbers are higher priority.
r   )rH   r   COMMAr   )rE   s    r9   rT   rT      s     yyEKKr8   NrA   c                    [        U [        [        -  S9(       a  gU R                  [        R
                  :X  af  U R                  (       aU  U R                  R                  [        R                  [        R                  1;  a  Ub  UR                  [        ;   a  [        $ U R                  [        ;   a\  U R                  (       aK  U R                  R                  [        R                  [        R                  1;  a  [        U R                     $ U R                  [         ;   a  ["        $ U R                  [        R$                  :X  a'  Ub$  UR                  [        R$                  :X  a  [&        $ U R                  [        R(                  [        R*                  1;  a  gU R,                  S:X  aI  U R                  (       a8  U R                  R                  [        R.                  [        R0                  1;   d  U R                  [        R*                  :X  a?  [3        U R4                  [6        5      (       a  U R4                  R,                  S:w  a  [8        $ U R,                  S:X  aO  U R                  (       a>  U R                  R                  [        R:                  [        R<                  1;   a  [8        $ U R,                  S;   a?  U R                  (       a.  U R                  R                  [        R>                  :X  a  [@        $ U R,                  S:X  a  ["        $ U R,                  S:X  a  U R                  (       ao  U R                  R                  [        RB                  [        RD                  1;   a7  Ub.  UR                  [        R(                  :X  a  UR,                  S	:X  d  ["        $ U R,                  S	:X  ap  U R                  (       a_  U R                  R                  [        RB                  :X  a7  Ub.  UR                  [        R(                  :X  a  UR,                  S:X  d  ["        $ U R,                  [F        ;   a  U R                  (       a  [H        $ g)
zReturn the priority of the `leaf` delimiter, given a line break before it.

The delimiter priorities returned here are from those delimiters that would
cause a line break before themselves.

Higher numbers are higher priority.
)withinr   r{   asyncif>   r   elseisr   not)%r   r   r   rH   r   DOTparentr   import_fromdotted_namer   r-   r   factor	star_exprr+   r   r"   STRINGr    r|   ASYNCrO   comp_forold_comp_for
isinstanceprev_siblingr   r   comp_ifold_comp_iftestr   comp_op
comparisonr   r   )rE   rA   s     r9   rR   rR      s    o0AAB  			UYYKKKKT%5%5t7G7G$HH2B!B 			^#KKKKT[[$..$AAtyy))yyK"" 			U\\! MMU\\)yyU[[11 	

eKKKK0A0A BB99# 4,,d33  &&'1)) 	

dKKKKt/?/? @@%%zz^#8H8HDII8UzzT"" 	

dKKKKt ?? +%' #" 	

eKKKK, +$& #"zz_$r8   nodec                    U R                   [        R                  :w  a  gU R                  S   nU R                  S   nUR                   [        R
                  :X  a  UR                   [        R                  :X  d  g[        5       nU R                  SS  HS  n[        U[        5      (       a  UR                  U5        M+  UR                  5        H  nUR                  U5        M     MU      UR                  5       $ ! [         a     gf = f)zReturn maximum delimiter priority inside `node`.

This is specific to atoms with contents contained in a pair of parentheses.
If `node` isn't an atom or there are no enclosing parentheses, returns 0.
r   r   r,   )rH   r   atomchildrenr   LPARRPARr;   r   r   rZ   leavesro   
ValueError)r   firstlastbtcrE   s         r9   max_delimiter_priority_in_atomr   I  s     yyDIIMM!E==DJJ%**$ejj)@		B]]1R aGGAJ
 #	 !((** s   ,C< <
D	D	r   c                 ,    [        S [        U 5       5       5      n/ n[        5       n[	        U[        U 5      5       H  nX   nUR                  [        ;   a$  UR                  [        UR                     U45        UR                  [        ;   d  MU  U(       a[  UR                  US   S   :X  aE  UR                  5       u  pg[	        XtS-   5       H  nUR                  [        X   5      5        M!     M    U$    U$ ! [         a    [        5       s $ f = f)zReturn leaves that are inside matching brackets.

The input `leaves` can have non-matching brackets at the head or tail parts.
Matching brackets are included.
c              3   V   #    U  H  u  pUR                   [        ;   d  M  Uv   M!     g 7frg   )rH   r   )rh   ils      r9   rk   6get_leaves_inside_matching_brackets.<locals>.<genexpr>m  s$      
+$!qvv9I/IAA+s   )	)r   r   r,   )next	enumerateStopIterationsetrangelenrH   r   rP   r
   r   rL   addrS   )	r   start_indexbracket_stackidsr   rE   _startjs	            r9   #get_leaves_inside_matching_bracketsr   e  s     
#F+
 

 M
%C;F,y99((  '$))"4a!8999((mB.?.B!B(,,.u!e,AGGBvyM* - J - J  us   C< <DDrg   )@r6   collections.abcr   r   dataclassesr   r   typingr   r   r	   black.nodesr
   r   r   r   r   r   r   r   r   r   blib2to3.pgen2r   blib2to3.pytreer   r   LNr   r   r   r   r   r   r   r   r   r   r    r"   VBAR
CIRCUMFLEXAMPER	LEFTSHIFT
RIGHTSHIFTPLUSMINUSSTARSLASHDOUBLESLASHPERCENTATTILDE
DOUBLESTARr+   r-   	Exceptionr/   r;   rT   rR   r   r   r   r1   r8   r9   <module>r      s   2 . ( ) )   ! & 4:	 !#  "  %    U 	JJ	a	KK	OOQ	a	JJ	KK	JJ	KK	q	MM1	HHa	KK	a   e W	 W \D \D \D~4 H ]D ]HTN ]h ]@  8 3v; r8   