
    ^h                     h   S SK r S SKrS SKJrJrJr  S SKJrJr  S SK	J
r
JrJrJr  S SKJrJrJr  S SK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J r J!r!J"r"J#r#J$r$J%r%J&r&  S SK'J(r(  S S	K)J*r*  S S
K+J,r,J-r-  \" S5      r.\/r0\/r1\\,\-4   r2\ " S S5      5       r3\ " S S5      5       r4\ " S S5      5       r5\ " S S5      5       r6S\\.   S\\7\0\.4      4S jr8 S+S\3S\3S\9\,   S\:SS4
S jjr;SS.S\3S\S \<S\:4S! jjr=S\3S\:4S" jr>S#\4S$\/S\:4S% jr?S\3S&\,S$\/S\:4S' jr@S\3S(\,S$\/S\:4S) jrAS\3S\<4S* jrBg),    N)CallableIteratorSequence)	dataclassfield)OptionalTypeVarUnioncast)COMMA_PRIORITYDOT_PRIORITYBracketTracker)ModePreview)BRACKETSCLOSING_BRACKETSOPENING_BRACKETSSTANDALONE_COMMENTTEST_DESCENDANTSchild_towardsis_docstring	is_importis_multiline_stringis_one_sequence_betweenis_type_commentis_type_ignore_commentis_with_or_async_with_stmtmake_simple_prefixreplace_childsyms
whitespace)	str_width)token)LeafNodeTc            	       R   \ rS rSr% Sr\" SS9r\\S'   Sr	\
\S'   \" \S9r\\   \S	'   \" \S9r\\\\   4   \S
'   \" \S9r\\S'   Sr\\S'   Sr\\S'   Sr\\   \S'    S8S\S\S\SS4S jjrS9S\S\SS4S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r \S\4S j5       r!\S\4S j5       r"\S\4S j5       r#\S\4S j5       r$\S\4S  j5       r%\S\4S! j5       r&\S\4S" j5       r'SS#.S$\\(\/\4      S\4S% jjr)S\4S& jr*S\4S' jr+S\4S( jr,S\4S) jr-S\4S* jr.S+\S\4S, jr/S-\S\4S. jr0S\S\\   4S/ jr1S:S0 jr2S\S\4S1 jr3 S9S2\S\4\5\6\\
4      4S3 jjr7S;S4 jr8S\94S5 jr:S\4S6 jr;S7r<g)<Line'   z;Holds leaves and comments. Can be printed with `str(line)`.F)reprmoder   depthdefault_factoryleavescommentsbracket_trackerinside_bracketsshould_split_rhsNmagic_trailing_commaleafpreformattedtrack_bracketreturnc                    UR                   [        ;   =(       dG    UR                   [        R                  :H  =(       d#    [	        UR
                  R                  5       5      nU(       d  gUR                   [        R                  :X  a   U R                  (       a  U R                  SS2	 U R                  (       a>  U(       d7  U=R                  [        UU R                  U5      U R                  S9-  sl
        U R                  (       d  U(       a  U(       ay  U R                  R!                  U5        U R                  R"                  (       a  U R%                  U5      (       a  Xl        O&U R%                  U5      (       a  U R'                  5         U R)                  U5      (       d  U R                  R+                  U5        gg)a7  Add a new `leaf` to the end of the line.

Unless `preformatted` is True, the `leaf` will receive a new consistent
whitespace prefix and metadata applied by :class:`BracketTracker`.
Trailing commas are maybe removed, unpacked for loop variables are
demoted from being delimiters.

Inline comments are put aside.
N)complex_subscriptr+   )typer   r#   FSTRING_MIDDLEboolvaluestripCOLONis_class_paren_emptyr/   prefixr!   is_complex_subscriptr+   r2   r1   markr4   has_magic_trailing_commaremove_trailing_commaappend_commentappend)selfr5   r6   r7   	has_values        E/home/james-whalen/.local/lib/python3.13/site-packages/black/lines.pyrI   Line.append5   s;    II! (yyE000( DJJ$$&'	 	 99#(A(ABC ;;| KK:"&";";D"AYY K
 |}  %%d+yy--006604-..t44**,""4((KKt$ )    c                 ,   U R                   R                  S:X  d  U R                   R                  5       (       aL  U R                  (       a  [	        S5      eU R
                  (       a  UR                  [        :X  a  [	        S5      eU R                  XS9  g)zLike :func:`append()` but disallow invalid standalone comment structure.

Raises ValueError when any `leaf` is appended after a standalone comment
or when a standalone comment is not the first leaf on the line.
r   z$cannot append to standalone commentsz5cannot append standalone comments to a populated liner6   N)	r1   r,   any_open_for_or_lambda
is_comment
ValueErrorr/   r<   r   rI   )rJ   r5   r6   s      rL   append_safeLine.append_safe^   ss       &&!+##::<< !GHH{{tyy,>> K  	D4rN   c                     [        U R                  5      S:H  =(       a     U R                  S   R                  [        :H  $ )z"Is this line a standalone comment?   r   )lenr/   r<   r   rJ   s    rL   rR   Line.is_commentr   s1     4;;1$RQ)<)<@R)RRrN   c                 z    [        U 5      =(       a*    U R                  S   R                  [        R                  :H  $ )zIs this line a decorator?r   )r>   r/   r<   r#   ATrY   s    rL   is_decoratorLine.is_decoratorw   s*     Dz=dkk!n11UXX==rN   c                 V    [        U 5      =(       a    [        U R                  S   5      $ )zIs this an import line?r   )r>   r   r/   rY   s    rL   r   Line.is_import|   s      Dz7iA77rN   c                 V    [        U 5      =(       a    [        U R                  S   5      $ )zIs this a with_stmt line?r   )r>   r   r/   rY   s    rL   r   Line.is_with_or_async_with_stmt   s!     DzH8QHHrN   c                     [        U 5      =(       aM    U R                  S   R                  [        R                  :H  =(       a    U R                  S   R
                  S:H  $ )z Is this line a class definition?r   class)r>   r/   r<   r#   NAMEr?   rY   s    rL   is_classLine.is_class   sJ     J 0A##uzz10A$$/	
rN   c                     U R                   =(       aD    U R                  SS [        S5       Vs/ s H  n[        [        R
                  S5      PM     sn:H  $ s  snf )zEIs this line a class definition with a body consisting only of "..."?N   .)rf   r/   ranger$   r#   DOTrJ   _s     rL   is_stub_classLine.is_stub_class   sR     }} 
RS!1*/(6
*2QDC (6
 "
 	
 6
s   $Ac                     U R                   S   n U R                   S   nUR                  [        R                  :H  =(       a    UR
                  S:H  =(       db    UR                  [        R                  :H  =(       a>    USL=(       a3    UR                  [        R                  :H  =(       a    UR
                  S:H  $ ! [         a     gf = f! [         a    Sn Nf = f)zBIs this a function definition? (Also returns True for async defs.)r   FrW   Ndef)r/   
IndexErrorr<   r#   re   r?   ASYNC)rJ   
first_leafsecond_leafs      rL   is_defLine.is_def   s    	QJ	*.++a.K 5::-K*2B2Be2K 
OOu{{* +4'+  EJJ.+ !!U*		
  		
  	K	s"   B= C =
C
	C
CCc           	          U R                   =(       a`    U R                  SS [        [        R                  S5      /[        S5       Vs/ s H  n[        [        R                  S5      PM     sn-   :H  $ s  snf )zHIs this line a function definition with a body consisting only of "..."?N:rj   rk   )rx   r/   r$   r#   rA   rl   rm   rn   s     rL   is_stub_defLine.is_stub_def   sj     {{ 
t{{23/Dc4J3K*/(O
*2QDC (O
 4
  
 	
 O
s   	$A4c                    [        U 5      =(       a    [        U R                  5      S:H  =(       a    U R                  =(       a    U R                  S   R                  [
        R                  :H  =(       ap    U R                  S   R                  S:H  =(       aM    U R                  S   R                  [
        R                  :H  =(       a    U R                  S   R                  S:H  $ )zjIs this a class with no base classes but using parentheses?

Those are unnecessary and should be removed.
      (rj   ))	r>   rX   r/   rf   r<   r#   LPARr?   RPARrY   s    rL   rB   Line.is_class_paren_empty   s     J ,DKK A%,, A##uzz1, A$$+	,
 A##uzz1, A$$+	
rN   c                     U (       a+  U R                   S   R                  [        R                  :w  a  gU R                   S   R                  nUR                  S5      (       a  gUR                  S5      (       a  gg)z#Is the line a triple quoted string?r   F)z"""z'''T)zr'''zr"""zR'''zR""")r/   r<   r#   STRINGr?   
startswith)rJ   r?   s     rL   _is_triple_quoted_stringLine._is_triple_quoted_string   sb     t{{1~**ell:A$$N++<==rN   c                 V    [        U 5      =(       a    [        U R                  S   5      $ )zIs the line a docstring?r   )r>   r   r/   rY   s    rL   r   Line.is_docstring   s      Dz:l4;;q>::rN   c                     U R                    Vs/ s H  oR                  PM     snR                  [        R                  5      S:  $ s  snf )z Is the line a chained assignmentrW   )r/   r<   countr#   EQUALrJ   r5   s     rL   is_chained_assignmentLine.is_chained_assignment   s6     '+kk2kd		k288EII2s   Ac                     [        U R                  5      S:X  a  gU R                  S   R                  [        R                  :H  $ )z/Does this line open a new level of indentation.r   F)rX   r/   r<   r#   rA   rY   s    rL   opens_blockLine.opens_block   s5     t{{q {{2##u{{22rN   first_leaf_matchesr   c                    [        U R                  5      S:w  a  gU R                  S   nUR                  [        :w  d  UR                  c  gUSL =(       d    U" UR                  5      $ )zIs this line converted from fmt off/skip code?

If first_leaf_matches is not None, it only returns True if the first
leaf of converted code matches.
rW   Fr   N)rX   r/   r<   r   fmt_pass_converted_first_leaf)rJ   r   r5   s      rL   is_fmt_pass_convertedLine.is_fmt_pass_converted   sd     t{{q {{1~II++119!T) 
-?...
 	
rN   c                 V    U R                    H  nUR                  [        :X  d  M    g   g)z)If so, needs to be split before emitting.TF)r/   r<   r   r   s     rL   contains_standalone_comments!Line.contains_standalone_comments   s%    KKDyy..   rN   c                    [         R                  " U R                  S 5       HY  u  pU[        R                  :w  a  M  [        U5      n[        U5      S:X  a  M7  U H  nU R                  U5      (       d  M      g   M[     g)zFChck if we have an implicit multiline string with comments on the linec                     U R                   $ N)r<   )r5   s    rL   <lambda>GLine.contains_implicit_multiline_string_with_comments.<locals>.<lambda>   s    diirN   rW   TF)	itertoolsgroupbyr/   r#   r   listrX   comments_after)rJ   	leaf_typeleaf_group_iterator	leaf_listr5   s        rL   0contains_implicit_multiline_string_with_comments5Line.contains_implicit_multiline_string_with_comments   sr    .7.?.?KK//
*I ELL(01I9~"!&&t,, "/
 rN   c                 6   [        5       n U R                  S   nUR                  [        U5      5        UR                  [
        R                  :X  d/  UR                  [
        R                  :X  a:  UR                  (       d)  U R                  S   nUR                  [        U5      5        SnU R                  R                  5        H?  u  pEU H4  n[        U5      (       a  U(       d  [        U5      (       d  XA;  a      gSnM6     MA     g! [         a     gf = f)Nr   r:   FT)setr/   addidr<   r#   COMMAr   r?   rt   r0   itemsr   r   )rJ   ignored_ids	last_leafcomment_seenleaf_idr0   comments          rL   $contains_uncollapsable_type_comments)Line.contains_uncollapsable_type_comments  s    e	BIOOByM*~~,%**,Y__ !KKO	9. !%!4!4!6G#"7++#27;;#6## $ "7 )  		s   BD 
DDc                 b   U R                   (       d  g[        S U R                    5       S5      n[        S [        U R                   5       5       S5      nX:X  aU  U R                   SS   HB  nU R                  R	                  [        U5      / 5       H  n[        U5      (       d  M      g   MD     g)NFc              3   \   #    U  H"  oR                   S :w  d  M  UR                   v   M$     g7fr   Nlineno.0r5   s     rL   	<genexpr>9Line.contains_unsplittable_type_ignore.<locals>.<genexpr>=  s      S;4++QRBR;4;;;   ,,r   c              3   \   #    U  H"  oR                   S :w  d  M  UR                   v   M$     g7fr   r   r   s     rL   r   r   ?  s!     O%:TkkQ>N[T[[%:r   r:   T)r/   nextreversedr0   getr   r   )rJ   
first_line	last_linenoder   s        rL   !contains_unsplittable_type_ignore&Line.contains_unsplittable_type_ignore,  s    {{ S4;;SUVW
OXdkk%:OQR
	 " BC(#}}00D2>G-g66#  ? )
 rN   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )r   r   s     rL   r   2Line.contains_multiline_strings.<locals>.<genexpr>N  s     E&t,,   )anyr/   rY   s    rL   contains_multiline_stringsLine.contains_multiline_stringsM  s    EEEErN   closingc                 *   UR                   [        ;   a<  U R                  (       a+  U R                  S   R                   [        R                  :X  d  gUR                   [        R
                  :X  a  gUR                   [        R                  :X  a  UR                  b  UR                  R                   [        R                  :X  a  UR                  b}  [        UR                  UU R                  [        R                  [        R                  4S9(       a:  UR                  c   eUR                  R                   [        R                  :X  d   eggU R                  (       a  gUR                  b&  [        UR                  XR                  5      (       d  gg)zReturn True if we have a magic trailing comma, that is when:
- there's a trailing comma here
- it's not from single-element square bracket indexing
- it's not a one-tuple
r   FT)brackets)r<   r   r/   r#   r   RBRACERSQBparentr    traileropening_bracketr   LSQBprev_siblingsubscriptlistr   )rJ   r   s     rL   rF   Line.has_magic_trailing_commaP  s#    LL,,B$$3<<5<<'<<5::%*NN''4<<7++7+++KK#jj%**5	 ++777++00D4F4FFFF>>"".7N##Wkk8
 8
 rN   r   c                    UR                   [        :X  a'  U R                  R                  5       (       a  SUl        gUR                   [
        R                  :w  a  gU R                  (       d  [        Ul         SUl        gU R                  S   nUR                   [
        R                  :X  a  UR                  (       d  UR                  (       a{  [        [        UR                  R                  5       5      5      S::  aK  [        U5      (       d;  [        U R                  5      S:  a  [        Ul         SUl        gU R                  S   nU R                  R                  [!        U5      / 5      R#                  U5        g)z0Add an inline or standalone comment to the line. Fr   rj   r   r:   T)r<   r   r1   any_open_bracketsrC   r#   COMMENTr/   r   r?   r   rX   r   r   r0   
setdefaultr   rI   )rJ   r   r   s      rL   rH   Line.append_comment|  s    LL..$$6688GN<<5==({{-GLGNKKO	NNejj(OO  D))002349#G,,
 4;;!#1!#BI  I3::7CrN   c                 L    U R                   R                  [        U5      / 5      $ )z;Generate comments that should appear directly after `leaf`.)r0   r   r   r   s     rL   r   Line.comments_after  s    }}  D2..rN   c                    U R                   R                  5       nU R                  R                  [        U5      / 5      nU R                  R	                  [        U R                   S   5      / 5      R                  U5        g)z@Remove the trailing comma and moves the comments attached to it.r   N)r/   popr0   r   r   extend)rJ   trailing_commatrailing_comma_commentss      rL   rG   Line.remove_trailing_comma  s]    *"&--"3"3B~4F"K  DKKO!4b9@@#	
rN   c                 f   U R                   R                  5       nUc  gUR                  n[        U[        5      (       aH  UR
                  [        R                  :X  a  gUR
                  [        R                  :X  a  [        X15      nUSL=(       a     [        S UR                  5        5       5      $ )zAReturn True iff `leaf` is part of a slice with non-trivial exprs.NFc              3   F   #    U  H  oR                   [        ;   v   M     g 7fr   )r<   r   )r   ns     rL   r   ,Line.is_complex_subscript.<locals>.<genexpr>  s      3
0K1FF&&0Ks   !)r1   get_open_lsqbnext_sibling
isinstancer%   r<   r    	listmakerr   r   r   	pre_order)rJ   r5   	open_lsqbsubscript_starts       rL   rD   Line.is_complex_subscript  s    ((668	#00ot,,##t~~5##t'9'99"/"Fd* 
s 3
0?0I0I0K3
 0
 	
rN   is_reversedc              #     #    [        [        [        [           /[        [
        [        [        4      4   U(       a  [        O[        5      nU" U R                  5       Hx  u  p4[        UR                  5      [        UR                  5      -   nSUR                  ;   a    gU R                  U5       H  nU[        UR                  5      -  nM     X4U4v   Mz     g7f)ztReturn an enumeration of leaves with their length.

Stops prematurely on multiline strings and standalone comments.

N)r   r   r   r$   r   tupleIndexenumerate_reversed	enumerater/   rX   rC   r?   r   )rJ   r   opindexr5   lengthr   s          rL   enumerate_with_lengthLine.enumerate_with_length  s      htn%xeTk0B'CCD"-9
 dkk?KE%DJJ7Ftzz!..t4#gmm,, 5 v%% +s   CCc                     [        U R                  U R                  U R                  U R                  U R
                  S9$ )N)r+   r,   r2   r3   r4   )r(   r+   r,   r2   r3   r4   rY   s    rL   clone
Line.clone  s8    ** 00!22!%!:!:
 	
rN   c                    U (       d  gSU R                   -  n[        U R                  5      n[        U5      nUR                   U UR
                   3nUSR                  S U 5       5      -  n[        R                  R                  U R                  R                  5       5      nU Vs/ s H  n[        U5      PM     nnUSR                  U5      -  nUS-   $ s  snf )zRender the line.r   z    r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )strr   s     rL   r   Line.__str__.<locals>.<genexpr>  s     4VTs4yyVr   )r,   iterr/   r   rC   r?   joinr   chainfrom_iterabler0   valuesr  )rJ   indentr/   firstrescomments_iterr   r0   s           rL   __str__Line.__str__  s    $**$dkk"Vvhu{{m4rww4V444!55dmm6J6J6LM0=>WCL>rwwx  Tz ?s   *Cc                 R    [        U R                  =(       d    U R                  5      $ )z/Return True if the line has leaves or comments.)r>   r/   r0   rY   s    rL   __bool__Line.__bool__  s    DKK04==11rN   )r4   )FFF)r8   N)r8   r(   )=__name__
__module____qualname____firstlineno____doc__r   r+   r   __annotations__r,   intr   r/   r$   dictr0   LeafIDr   r1   r2   r>   r3   r4   r   rI   rT   propertyrR   r]   r   r   rf   rp   rx   r}   rB   r   r   r   r   r   r   r   r   r   r   r   rF   rH   r   rG   rD   r   r   r   r  r	  r  r  r  __static_attributes__ rN   rL   r(   r(   '   s:   EE"D$"E3Nt4FDJ4).t)DHd64:%&D&+N&KO^K!OT!"d"+/(4./ MR'%'%(,'%EI'%	'%R5 5D 5T 5( SD S S >d > > 84 8 8 ID I I 
$ 
 
 
t 
 
 
 
 
$ 
T 
 
 
d 
 
 	$ 	 	 ;d ; ; Jt J J 3T 3 3 IM
%-hvt|.D%E
	
(d $ "d "H4 BFD F* * *X#d #t #J/4 /DJ /

 
$ 
( #(&&	%tS()	*&*
  2$ 2rN   r(   c                   L    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   Srg	)
	RHSResulti  z2Intermediate split result from a right hand split.headbodytailr   closing_bracketr)  N)	r  r  r   r!  r"  r(   r#  r$   r(  r)  rN   rL   r+  r+    s     <
J
J
JrN   r+  c                       \ rS rSr% Sr\\S'   \S    \S'   \\S'   Sr	\
\S'   \" \S9r\\   \S	'   Sr\
\S
'   Sr\\S'   S\\   4S jrSrg)
LinesBlocki  zClass that holds information about a block of formatted lines.

This is introduced so that the EmptyLineTracker can look behind the standalone
comments and adjust their empty lines for class or def lines.
r+   previous_blockoriginal_liner   beforer-   content_linesafterF	form_feedr8   c                     [        [        U R                  S95      n[        U R                  U R
                  U5      nU/U R                  -   XR                  -  /-   $ )N)r+   )r  r(   r+   r   r4  r7  r5  r6  )rJ   
empty_linerC   s      rL   	all_linesLinesBlock.all_lines  sM    499-.
#DKKLx$,,,
ZZ0G/HHHrN   r)  N)r  r  r   r!  r"  r   r#  r   r(   r4  r$  r   r   r5  r  r6  r7  r>   r:  r(  r)  rN   rL   r1  r1    s`     J\**FCO$T:M49:E3NItI49 IrN   r1  c            
           \ rS rSr% Sr\\S'   Sr\\	   \S'   Sr
\\   \S'   \" \S9r\\	   \S'   Sr\\   \S	'   S
\	S\4S jrS
\	S\\\4   4S jrS
\	S\S\S\\\4   4S jrSrg)EmptyLineTrackeri  ag  Provides a stateful method that returns the number of potential extra
empty lines needed before and after the currently processed line.

Note: this tracker works on lines that haven't been split yet.  It assumes
the prefix of the first leaf consists of optional newlines.  Those newlines
are consumed by `maybe_empty_lines()` and included in the computation.
r+   Nprevious_liner2  r-   previous_defssemantic_leading_commentcurrent_liner8   c           	         UR                   S:H  =(       a8    [        UR                  5      =(       a    SUR                  S   R                  ;   nU R	                  U5      u  p4U R
                  (       a  U R
                  R                  OSn[        SX5-
  5      nU R
                  (       a  U R
                  R
                  cv  [        U R
                  R                  R                  5      S:X  aI  U R
                  R                  R                  (       a$  UR                  (       d  UR                  (       d  Sn[        U R                  U R
                  UUUUS9nUR                  (       ae  U R                   bQ  U R                   R"                  (       d<  U R                   R                  (       a  U(       a  U R$                  b  U(       a  X`l        OUR"                  (       a  U(       a  SU l        Xl        X`l        U$ )zReturn the number of extra empty lines before and after the `current_line`.

This is for separating `def`, `async def` and `class` with extra empty
lines (two on module-level).
r   z
NrW   )r+   r2  r3  r4  r6  r7  )r,   r>   r/   rC   _maybe_empty_linesr2  r6  maxrX   r3  r   rf   rx   r1  r+   rR   r>  r]   r@  )rJ   rA  r7  r4  r6  previous_afterblocks          rL   maybe_empty_lines"EmptyLineTracker.maybe_empty_lines$  s    !# 8\(()8,--a0777 	
 //=6:6I6I,,22qQ/0 ##22:D''55<<=B##11>>!**l.A.AF..&
 ""!!)&&33++66&22:f05-**f,0D))#rN   c                    SnUR                   S:X  a  U R                  R                  (       a  SOSnUR                  (       a=  UR                  S   nUR                  R                  S5      n[        XB5      nSUl        OSn[        U5      nUR                   nS nU R                  (       ag  U R                  S   R                   U:  aJ  U R                  R                  5       nU R                  (       a  U R                  S   R                   U:  a  MJ  UR                  (       d  UR                  (       a  U R                  R                  U5        U R                  c  gUR                  (       aS  U R                  R                  (       a  gU R                  R                  (       a  U R                  R                  (       a  gUGb
  U R                  c   eU R                  R                  (       aq  UR                  (       a  UR                   (       d  SnOU(       a8  UR                  (       d'  U R                  R                  (       a  U(       a  SOSnO|U(       a  SnOrSnOoU(       a  SnOeU(       d\  UR                   (       aK  UR                  S   R"                  [$        R&                  :X  a   UR                  S   R(                  S	;  a  SnOSnUR*                  (       d"  UR                  (       d  UR                  (       a  U R-                  XU5      $ U R                  R.                  (       aZ  U R                  R                   S:X  a@  UR                   S:X  a0  UR.                  (       d  [0        R2                  U R                  ;   a  g
U R                  R.                  (       aO  UR.                  (       d>  UR5                  [.        S9(       d&  X`R                  R                   :X  a  U=(       d    SS4$ US4$ )NrW   r   r   r   r   r   r   r   r   rW   )withtryforwhileifmatch)rW   r   r   )r,   r+   is_pyir/   rC   r   minr>   r?  r   rx   rf   rI   r>  r   r   rp   r<   r#   rA   r?   r]   #_maybe_empty_lines_for_class_or_defr   r   always_one_newline_after_importr   )rJ   rA  max_allowedrv   r4  user_had_newliner,   previous_defs           rL   rC  #EmptyLineTracker._maybe_empty_linesV  s   "#yy//!QK%,,Q/J&&,,T2F-F "JF<""   T%7%7%;%A%AU%J--113L   T%7%7%;%A%AU%J,"7"7%%l3%$$!!**!!--$2D2D2K2K#%%111yy((1K1KF<#6#64;M;M;T;T"2QFFFF$**$++B/44C$++A.44MN FF$$(;(;|?T?T;;&6 
 ((""((A-""a' **77499D (( ** 66)6T++111Ka!##qyrN   r4  rW  c                    U R                   c   eU R                   R                  (       a.  U R                  R                  (       a  UR                  (       a  ggU R                   R
                  UR
                  :  aa  U R                   R                  (       d  U R                   R                  (       a+  U R                  R                  (       a  gU(       a  SS4$ SS4$ S nU R                   R                  (       a  U R                   R
                  UR
                  :X  a  US:X  az  U R                  nUbj  UR                  b]  UR                  R                  R                  (       d8  UR                  R                  R                  (       d  UR                  S::  a  UnOgU R                  R                  (       Ga5  UR                  (       d  U R                   R                  (       a  U R                   R
                  UR
                  :  a  SnGOU R                   R
                  UR
                  :  a  SnOUR                  (       a  U R                   R                  (       a  SnOSnOU R                   R
                  UR
                  :  a  SnOUR                  (       d  UR                  (       a<  U R                   R                  (       d!  UR
                  (       a  [        SU5      nO?SnO<SnO9UR
                  (       a  SOSnU R                   R                  (       a	  U(       d  SnUb9  UR                  nUb*  [!        UR                  U5      UR"                  -
  Ul        SnUS4$ )NrK  rJ  rW   r   r   )r>  r]   r+   rR  rp   r,   rf   rx   rR   r@  r2  r3  r   r4  rS  r}   rD  r6  )rJ   rA  r4  rW  comment_to_add_newlinesslcnewlinesr2  s           rL   rT  4EmptyLineTracker._maybe_empty_lines_for_class_or_def  s    !!---**yyL$>$>##l&8&88''4+=+=+D+Dyy(122a228<))""((L,>,>>!//C&&2**88AA**88DDJJ!O*-'99$$(:(:(C(C%%++l.@.@@ H''--0B0BB H!//D4F4F4T4T H H ##))L,>,>>##|'@'@((//%%  #1f~H  !H(..qAH !!--6F".4CCN)/66ANDXDXX (. {rN   )r2  r>  r@  )r  r  r   r!  r"  r   r#  r>  r   r(   r2  r1  r   r   r?  r@  rG  r   r$  rC  r>   rT  r(  r)  rN   rL   r=  r=    s     J$(M8D>(+/NHZ(/ %d ;M4:;59hz290d 0z 0d[t [c3h [zN N*-NAEN	sCxNrN   r=  sequencer8   c              #   `   #    [        U 5      S-
  n[        U 5       H  nX4v   US-  nM     g7f)z;Like `reversed(enumerate(sequence))` if that were possible.rW   N)rX   r   )r_  r  elements      rL   r  r    s4     MAEH%
 &s   ,.new_lineold_liner/   r6   c                     U He  n[        UR                  UR                  5      n[        XE5        U R	                  XSS9  UR                  U5       H  nU R	                  USS9  M     Mg     g)a  
Append leaves (taken from @old_line) to @new_line, making sure to fix the
underlying Node structure where appropriate.

All of the leaves in @leaves are duplicated. The duplicates are then
appended to @new_line and used to replace their originals in the underlying
Node structure. Any comments attached to the old leaves are reattached to
the new leaves.

Pre-conditions:
    set(@leaves) is a subset of set(@old_line.leaves).
rP   TN)r$   r<   r?   r   rI   r   )rb  rc  r/   r6   old_leafnew_leafcomment_leafs          rL   append_leavesrh    s]     x~~6h)<$33H=LOOLtO< > rN   r   )line_strliner+   ri  c                D   U(       d  [        U 5      n[        R                  U;  a@  [        U5      UR                  :*  =(       a!    SU;  =(       a    U R                  5       (       + $ U R                  5       (       a  gSU;  a  [        U5      UR                  :*  $ UR                  S5      Gtp4n[        U5      UR                  :  d  [        U5      UR                  :  a  g/ nSn/ n[        R                  n	[        U R                  5       GHn  u  pU	[        R                  :X  a  SnUR                  S-   [        U5      :  a  UR                  S5        O,UR                  S-   [        U5      :  a  UR                  5       nUb4  Ub1  UR                  UR                  S-   :X  a  UR                  n	US:  a    gUR                  U	::  a  UR                  [         R"                  :X  aj  S/nX-  nU R$                  (       d  UR                  S:  aB  U
[        U R                  5      S-
  :w  d  UR&                  U;  a  XkR                  ==   S-  ss'   U	[        R                  :w  a  [)        XR                  5      n	[+        U5      (       d  GM  UR,                  (       aw  UR,                  R                  [.        R0                  :X  dM  UR,                  R,                  (       a4  UR,                  R,                  R                  [.        R2                  :X  a    g[        U5      S:  a    gUnUn[5        U5      U;   d  GM0  UR                  U5        UR,                  c  GMQ  UR,                  n[5        U5      U;   a  M>  GMq     [        U5      S:X  a  g[7        S U 5       5      $ )a  For non-multiline strings, return True if `line` is no longer than `line_length`.
For multiline strings, looks at the context around `line` to determine
if it should be inlined or split up.
Uses the provided `line_str` rendering, if any, otherwise computes a new one.
r   FNrW   r   Tc              3   *   #    U  H	  oS :H  v   M     g7fr   r)  )r   vals     rL   r   'is_line_short_enough.<locals>.<genexpr>  s     *6Cax6s   )line_to_stringr   multiline_string_handlingr"   line_lengthr   splitmathinfr  r/   bracket_depthrX   rI   r   r<   r#   r   r2   r   rS  r   r   r    testdictsetmakerr  all)rj  r+   ri  r  ro   lastcommasmultiline_stringmultiline_string_contextsmax_level_to_updateir5   	had_commaignore_ctxsctxs                  rL   is_line_short_enoughr  $  s    !$'((4h4#3#33 8H$85577	
 ((**8"d&6&666nnT*OEt$***io@P@P.P F'+*,-1XXT[[)$((*'+I!!A%F3a ##a'#f+5"JJL	%$0$22d6H6H16LL '+&8&8#q= !44ekk9Q 04fK4K$$(:(:Q(>S%))T->->k-Q))*a/*$((*"%&9;M;M"Nt$${{  DII-KK&&4;;+=+=+B+BdFWFW+W ,-1#Cc(h&)005::%jj	 c(h&&W *f $%**6***rN   c                    U R                   n[        U5      S:  a  gUS   R                  [        R                  :X  Ga  US   R                  [        R
                  :X  a  SnSnUS   nUSSS2    H  nUR                  [        ;   a  UR                  [        ;  a    gUS-  nOUR                  [        R
                  :X  a  US-  nOiUR                  [        R                  :X  a5  UR                  [        R
                  :X  d  UR                  [        ;   d    gOUR                  [        ;  a    gUS:  d  M  US:  d  M    g   g)	zReturn False if the line cannot be split *for sure*.

This is not an exhaustive search but a cheap heuristic that we can use to
avoid some unfortunate formattings (mostly around wrapping unsplittable code
in unnecessary parentheses).
r   Fr   rW   r   r:   NT)	r/   rX   r<   r#   r   rm   r   r   re   )rj  r/   
call_count	dot_countr   r5   s         rL   can_be_splitr    s     [[F
6{Qay~~%&)..EII*E
	bz26r6NDyy,,99$44 a
eii'Q	ejj(		UYY.$))?O2O "221}a! #$ rN   rhsrq  c                    U R                   nSn[        UR                  5       H  nU(       a  XCR                  L a  SnUR                  [
        :X  a	  U(       d    gU(       a  M@  UR                  [        ;   d  MV  UR                  UR                  ;   d  Mr  UR                  (       d  M  UnM     UR                  nUR                  (       d  gUR                  5       nUR                  U5      nUS:  a  gUS:X  a&  U[        :X  a  U R                  R                  (       a  gU[        :X  a  g[!        UR                  5      S:  d   S5       eUR                  S   nUR                  S   n	UR                  ["        ;   a$  U	R                  [        ;  a  [%        X(US9(       a  gUR                  S	   n
UR                  S
   nUR                  [&        R(                  :X  du  UR                  [&        R*                  :X  dW  UR                  [&        R,                  :X  ao  UR.                  (       a^  UR.                  R                  [0        R2                  :w  a6  U
R                  ["        ;   a  g[5        U5      (       a  g[7        X+US9(       a  gg)zDoes `rhs.body` have a shape safe to reformat without optional parens around it?

Returns True for only a subset of potentially nice looking formattings but
the point is to not return false positives that end up producing lines that
are too long.
NFTrW   r   zStranded delimiterr   )r  rq  r:   r   )ry  rq  )r-  r   r/   r   r<   r   r   r?   r1   
delimitersmax_delimiter_prioritydelimiter_count_with_priorityr   r,  r   r   rX   r   _can_omit_opening_parenr#   r   r   r   r   r    r   r   _can_omit_closing_paren)r  rq  rj  r/  r5   btmax_prioritydelimiter_countr  secondpenultimatery  s               rL   can_omit_invisible_parensr    s    88D '+O%t'F'FF"O99**?		--$$3


"O & 
		B==,,.L66|DO!>)chh.Q.Q
 
 |#t{{q 6"66  KKNE[[^Fzz%%&++=M*M"4+N ++b/K;;r?D 			UZZ99$ II#  DLL0 //u%% "4LrN   r  c                :   SnSU R                   -  nSnU R                  5        HW  u  pVnUR                  [        ;   a  UR                  UL a  SnU(       d  M4  XG-  nXB:  a    gUR                  [
        ;   d  MU  SnMY     [        U R                  5      US-   :X  a  gg) See `can_omit_invisible_parens`.Fr   r   TrW   )r,   r  r<   r   r   r   rX   r/   )rj  r  rq  	remainderr  _indexr5   leaf_lengths           rL   r  r  
  s    I^FF%)%?%?%A!k99((T-A-AU-JI9!F#  yy,,!	 &B t{{vz)rN   ry  c                    SU R                   -  nSnU R                  5        H@  u  pVnX7-  nXaR                  L a  U(       d  X2::  a    gM(  UR                  [        ;   d  M>  SnMB     g)r  r   FT)r,   r  r   r<   r   )rj  ry  rq  r  seen_other_bracketsr  r5   r  s           rL   r  r  #  sl    ^F%)%?%?%A!k'''"f&; '< YY**"& &B rN   c                 6    [        U 5      R                  S5      $ )zeReturns the string representation of @line.

WARNING: This is known to be computationally expensive.
r   )r  r@   )rj  s    rL   ro  ro  4  s    
 t9??4  rN   r  )Cr   rs  collections.abcr   r   r   dataclassesr   r   typingr   r	   r
   r   black.bracketsr   r   r   
black.moder   r   black.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   black.stringsr"   blib2to3.pgen2r#   blib2to3.pytreer$   r%   r&   r$  r   r&  LNr(   r+  r1  r=  r   r  r   r>   rh  r  r  r  r  r  r  ro  r)  rN   rL   <module>r     s     8 8 ( 1 1 G G $    & $   & CL	
4: H2 H2 H2V    I I I* l l l^! %q/1J  NS=="=,0J=FJ=	=2 02^+
^+^+),^+	^+B!t ! !H^	^^ 
^B$ $ S T 2$  C D "! !# !rN   