
    h                     T   d dl Z d dlZd dlmZmZmZ d dlmZmZ d dl	m
Z
mZmZmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z( d d	l)m*Z* d d
l+m,Z,m-Z-  ed      Z.e/Z0e/Z1ee,e-f   Z2e G d d             Z3e G d d             Z4e G d d             Z5e G d d             Z6dee.   dee7e0e.f      fdZ8	 d+de3de3de9e,   de:ddf
dZ;ddde3ded e<de:fd!Z=de3de:fd"Z>d#e4d$e/de:fd%Z?de3d&e,d$e/de:fd'Z@de3d(e,d$e/de:fd)ZAde3de<fd*ZBy),    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            	          e Zd ZU dZ ed      Zeed<   dZe	ed<    ee
      Ze
e   ed<    ee      Zeee
e   f   ed	<    ee      Zeed
<   dZeed<   dZeed<   dZee   ed<   	 d6dedededdfdZd7dededdfdZedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Zedefd       Z edefd       Z!edefd       Z"edefd       Z#edefd       Z$edefd        Z%edefd!       Z&dd"d#ee'egef      defd$Z(defd%Z)defd&Z*defd'Z+defd(Z,defd)Z-d*edefd+Z.d,edefd-Z/dede
e   fd.Z0d8d/Z1dedefd0Z2	 d7d1ede3e4e5ee	f      fd2Z6d9d3Z7de8fd4Z9defd5Z:y):Linez;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                    |j                   t        v xsB |j                   t        j                  k(  xs# t	        |j
                  j                               }|sy|j                   t        j                  k(  r| j                  r| j                  dd= | j                  r<|s:|xj                  t        || j                  |      | j                        z  c_
        | j                  s|r|rk| j                  j!                  |       | j                  j"                  r| j%                  |      r)|| _        n!| j%                  |      r| j'                          | j)                  |      s| j                  j+                  |       yy)ag  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*   r1   r0   markr3   has_magic_trailing_commaremove_trailing_commaappend_commentappend)selfr4   r5   r6   	has_values        >/var/www/html/immo/lib/python3.12/site-packages/black/lines.pyrH   zLine.append5   s3    II! (yyE000( DJJ$$&'	 	 99#(A(ABC ;;| KK:"&";";D"AYY K
 |}  %%d+yy--00604D-..t4**,""4(KKt$ )    c                    | j                   j                  dk(  s| j                   j                         rA| j                  rt	        d      | j
                  r|j                  t        k(  rt	        d      | j                  ||       y)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r5   N)	r0   r+   any_open_for_or_lambda
is_comment
ValueErrorr.   r;   r   rH   )rI   r4   r5   s      rK   append_safezLine.append_safe^   sr       &&!+##::< !GHH{{tyy,>> K  	D|4rL   c                 v    t        | j                        dk(  xr  | j                  d   j                  t        k(  S )z"Is this line a standalone comment?   r   )lenr.   r;   r   rI   s    rK   rP   zLine.is_commentr   s1     4;;1$RQ)<)<@R)RRrL   c                 p    t        |       xr* | j                  d   j                  t        j                  k(  S )zIs this line a decorator?r   )r=   r.   r;   r#   ATrV   s    rK   is_decoratorzLine.is_decoratorw   s*     Dz=dkk!n11UXX==rL   c                 L    t        |       xr t        | j                  d         S )zIs this an import line?r   )r=   r   r.   rV   s    rK   r   zLine.is_import|   s      Dz7iA77rL   c                 L    t        |       xr t        | j                  d         S )zIs this a with_stmt line?r   )r=   r   r.   rV   s    rK   r   zLine.is_with_or_async_with_stmt   s!     DzH8QHHrL   c                     t        |       xrH | j                  d   j                  t        j                  k(  xr | j                  d   j
                  dk(  S )z Is this line a class definition?r   class)r=   r.   r;   r#   NAMEr>   rV   s    rK   is_classzLine.is_class   sJ     J 0A##uzz10A$$/	
rL   c                     | j                   xrA | j                  dd t        d      D cg c]  }t        t        j
                  d       c}k(  S c c}w )zEIs this line a class definition with a body consisting only of "..."?N   .)r_   r.   ranger$   r#   DOTrI   _s     rK   is_stub_classzLine.is_stub_class   sN     }} 
RS!1*/(6
%&DC 6
 "
 	
 6
s   !Ac                    	 | j                   d   }	 | j                   d   }|j                  t        j                  k(  xr |j
                  dk(  xsS |j                  t        j                  k(  xr4 |duxr. |j                  t        j                  k(  xr |j
                  dk(  S # t        $ r Y yw xY w# t        $ r d}Y w xY w)zBIs this a function definition? (Also returns True for async defs.)r   FrT   Ndef)r.   
IndexErrorr;   r#   r^   r>   ASYNC)rI   
first_leafsecond_leafs      rK   is_defzLine.is_def   s    	QJ	*.++a.K 5::-K*2B2Be2K 
OOu{{* +4'+  EJJ.+ !!U*		
  		
  	K	s"   B$ B3 $	B0/B03C Cc           	          | j                   xr] | j                  dd t        t        j                  d      gt        d      D cg c]  }t        t        j                  d       c}z   k(  S c c}w )zHIs this line a function definition with a body consisting only of "..."?N:rb   rc   )ro   r.   r$   r#   r@   rd   re   rf   s     rK   is_stub_defzLine.is_stub_def   sf     {{ 
t{{23/Dc4J3K*/(O
%&DC O
 4
  
 	
 O
s   !A,c                    t        |       xr t        | j                        dk(  xr | j                  xr | j                  d   j                  t
        j                  k(  xrf | j                  d   j                  dk(  xrH | j                  d   j                  t
        j                  k(  xr | j                  d   j                  dk(  S )zzIs this a class with no base classes but using parentheses?

        Those are unnecessary and should be removed.
              (rb   ))	r=   rU   r.   r_   r;   r#   LPARr>   RPARrV   s    rK   rA   zLine.is_class_paren_empty   s     J ,DKK A%,, A##uzz1, A$$+	,
 A##uzz1, A$$+	
rL   c                     | r*| j                   d   j                  t        j                  k7  ry| j                   d   j                  }|j                  d      ry|j                  d      ryy)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)rI   r>   s     rK   _is_triple_quoted_stringzLine._is_triple_quoted_string   s\     t{{1~**ell:A$$N+<=rL   c                 L    t        |       xr t        | j                  d         S )zIs the line a docstring?r   )r=   r   r.   rV   s    rK   r   zLine.is_docstring   s      Dz:l4;;q>::rL   c                     | j                   D cg c]  }|j                   c}j                  t        j                        dkD  S c c}w )z Is the line a chained assignmentrT   )r.   r;   countr#   EQUALrI   r4   s     rK   is_chained_assignmentzLine.is_chained_assignment   s4     '+kk2d		288EII2s   Ac                     t        | j                        dk(  ry| j                  d   j                  t        j                  k(  S )z/Does this line open a new level of indentation.r   F)rU   r.   r;   r#   r@   rV   s    rK   opens_blockzLine.opens_block   s5     t{{q {{2##u{{22rL   first_leaf_matchesr   c                    t        | j                        dk7  ry| j                  d   }|j                  t        k7  s|j                  y|du xs  ||j                        S )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.
        rT   Fr   N)rU   r.   r;   r   fmt_pass_converted_first_leaf)rI   r   r4   s      rK   is_fmt_pass_convertedzLine.is_fmt_pass_converted   sd     t{{q {{1~II++119!T) 
-?...
 	
rL   c                 P    | j                   D ]  }|j                  t        k(  s y y)z)If so, needs to be split before emitting.TF)r.   r;   r   r   s     rK   contains_standalone_commentsz!Line.contains_standalone_comments   s*    KK 	Dyy..	 rL   c                     t        j                  | j                  d       D ]N  \  }}|t        j                  k7  rt        |      }t        |      dk(  r4|D ]  }| j                  |      s  y P y)zFChck if we have an implicit multiline string with comments on the linec                     | j                   S N)r;   )r4   s    rK   <lambda>zGLine.contains_implicit_multiline_string_with_comments.<locals>.<lambda>   s
    dii rL   rT   TF)	itertoolsgroupbyr.   r#   r|   listrU   comments_after)rI   	leaf_typeleaf_group_iterator	leaf_listr4   s        rK   0contains_implicit_multiline_string_with_commentsz5Line.contains_implicit_multiline_string_with_comments   s|    .7.?.?KK//
 
	 *I* ELL(01I9~"!  &&t, 
	  rL   c                     t               }	 | j                  d   }|j                  t        |             |j                  t
        j                  k(  s)|j                  t
        j                  k(  r5|j                  s)| j                  d   }|j                  t        |             d}| j                  j                         D ]-  \  }}|D ]#  }t        |      r|st        |      s||vr  yd}% / y# t        $ r Y yw xY w)Nr   r9   FT)setr.   addidr;   r#   COMMArz   r>   rk   r/   itemsr   r   )rI   ignored_ids	last_leafcomment_seenleaf_idr/   comments          rK   $contains_uncollapsable_type_commentsz)Line.contains_uncollapsable_type_comments  s    e	BIOOByM*~~,%**,Y__ !KKO	9. !%!4!4!6 		$GX# $"7+#27;#;6##$		$ )  		s   BC1 1	C=<C=c                 F   | j                   syt        d | j                   D        d      }t        d t        | j                         D        d      }||k(  rL| j                   dd  D ]:  }| j                  j	                  t        |      g       D ]  }t        |      s  y < y)NFc              3   T   K   | ]   }|j                   d k7  s|j                    " ywr   Nlineno.0r4   s     rK   	<genexpr>z9Line.contains_unsplittable_type_ignore.<locals>.<genexpr>=  s      S4$++QRBR4;;S   ((r   c              3   T   K   | ]   }|j                   d k7  s|j                    " ywr   r   r   s     rK   r   z9Line.contains_unsplittable_type_ignore.<locals>.<genexpr>?  s     OTdkkQ>NT[[Or   r9   T)r.   nextreversedr/   getr   r   )rI   
first_line	last_linenoder   s        rK   !contains_unsplittable_type_ignorez&Line.contains_unsplittable_type_ignore,  s    {{ S4;;SUVW
OXdkk%:OQR
	 " BC( $#}}00D2> $G-g6#$$
 rL   c                 :    t        d | j                  D              S )Nc              3   2   K   | ]  }t        |        y wr   )r   r   s     rK   r   z2Line.contains_multiline_strings.<locals>.<genexpr>N  s     E&t,E   )anyr.   rV   s    rK   contains_multiline_stringszLine.contains_multiline_stringsM  s    EEEErL   closingc                    |j                   t        v r6| j                  r*| j                  d   j                   t        j                  k(  sy|j                   t        j
                  k(  ry|j                   t        j                  k(  r|j                  |j                  j                   t        j                  k(  r|j                  yt        |j                  || j                  t        j                  t        j                  f      r8|j                  J |j                  j                   t        j                  k(  sJ yy| j                  ry|j                  "t        |j                  || j                        syy)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   )rI   r   s     rK   rE   z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##Wdkk8
 rL   r   c                    |j                   t        k(  r"| j                  j                         rd|_        y|j                   t
        j                  k7  ry| j                  st        |_         d|_        y| j                  d   }|j                   t
        j                  k(  r|j                  s|j                  rtt        t        |j                  j                                     dk  rEt        |      s:t        | j                        dk  rt        |_         d|_        y| j                  d   }| j                  j                  t!        |      g       j#                  |       y)z0Add an inline or standalone comment to the line. Fr   rb   rv   r9   T)r;   r   r0   any_open_bracketsrB   r#   COMMENTr.   rz   r>   r   rU   r   r   r/   
setdefaultr   rH   )rI   r   r   s      rK   rG   zLine.append_comment|  s    LL..$$66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rL   c                 L    | j                   j                  t        |      g       S )z;Generate comments that should appear directly after `leaf`.)r/   r   r   r   s     rK   r   zLine.comments_after  s    }}  D2..rL   c                    | j                   j                         }| j                  j                  t        |      g       }| j                  j	                  t        | j                   d         g       j                  |       y)z@Remove the trailing comma and moves the comments attached to it.r   N)r.   popr/   r   r   extend)rI   trailing_commatrailing_comma_commentss      rK   rF   zLine.remove_trailing_comma  s]    *"&--"3"3B~4F"K  DKKO!4b9@@#	
rL   c                 N   | j                   j                         }|y|j                  }t        |t              rG|j
                  t        j                  k(  ry|j
                  t        j                  k(  rt        ||      }|duxr  t        d |j                         D              S )zAReturn True iff `leaf` is part of a slice with non-trivial exprs.NFc              3   @   K   | ]  }|j                   t        v   y wr   )r;   r   )r   ns     rK   r   z,Line.is_complex_subscript.<locals>.<genexpr>  s      3
+,AFF&&3
s   )r0   get_open_lsqbnext_sibling
isinstancer%   r;   r    	listmakerr   r   r   	pre_order)rI   r4   	open_lsqbsubscript_starts       rK   rC   z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
 	
rL   is_reversedc              #     K   t        t        t        t           gt        t
        t        t        f      f   |rt        nt              } || j                        D ]u  \  }}t        |j                        t        |j                        z   }d|j                  v r y| j                  |      D ]  }|t        |j                        z  } |||f w yw)zReturn 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.   rU   rB   r>   r   )rI   r   opindexr4   lengthr   s          rK   enumerate_with_lengthzLine.enumerate_with_length  s      htn%xeTk0B'CCD"-9
 dkk? 	&KE4%DJJ7Ftzz!..t4 -#gmm,,- v%%	&s   CCc                     t        | j                  | j                  | j                  | j                  | j
                        S )N)r*   r+   r1   r2   r3   )r(   r*   r+   r1   r2   r3   rV   s    rK   clonez
Line.clone  s8    ** 00!22!%!:!:
 	
rL   c                    | syd| j                   z  }t        | j                        }t        |      }|j                   | |j
                   }|dj                  d |D              z  }t        j                  j                  | j                  j                               }|D cg c]  }t        |       }}|dj                  |      z  }|dz   S c c}w )zRender the line.r   z    r   c              3   2   K   | ]  }t        |        y wr   )strr   s     rK   r   zLine.__str__.<locals>.<genexpr>  s     4Ts4y4r   )r+   iterr.   r   rB   r>   joinr   chainfrom_iterabler/   valuesr   )rI   indentr.   firstrescomments_iterr   r/   s           rK   __str__zLine.__str__  s    $**$dkk"Vvhu{{m4rww4V444!55dmm6J6J6LM0=>WCL>>rwwx  Tz ?s   %Cc                 H    t        | j                  xs | j                        S )z/Return True if the line has leaves or comments.)r=   r.   r/   rV   s    rK   __bool__zLine.__bool__  s    DKK04==11rL   )FFF)r7   N)r7   r(   );__name__
__module____qualname____doc__r   r*   r   __annotations__r+   intr   r.   r$   dictr/   LeafIDr   r0   r1   r=   r2   r3   r   rH   rR   propertyrP   rY   r   r   r_   rh   ro   rs   rA   r~   r   r   r   r   r   r   r   r   r   r   rE   rG   r   rF   rC   r   r   r   r   r   r   r   r    rL   rK   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$ 2rL   r(   c                   D    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   y)	RHSResultz2Intermediate split result from a right hand split.headbodytailr   closing_bracketN)r   r   r   r   r(   r   r$   r  rL   rK   r  r    s     <
J
J
JrL   r  c                       e Zd ZU dZeed<   ed    ed<   eed<   dZe	ed<    e
e      Zee   ed<   dZe	ed	<   d
Zeed<   dee   fdZy)
LinesBlockzClass 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_feedr7   c                     t        t        | j                              }t        | j                  | j
                  |      }|g| j                  z   || j                  z  gz   S )N)r*   )r   r(   r*   r   r  r  r  r  )rI   
empty_linerB   s      rK   	all_lineszLinesBlock.all_lines  sO    499-.
#DKKLx$,,,
TZZ0G/HHHrL   N)r   r   r   r   r   r   r   r(   r  r   r   r   r  r   r  r  r=   r  r  rL   rK   r  r    s`     J\**FCO$T:M49:E3NItI49 IrL   r  c            
           e Zd ZU dZeed<   dZee   ed<   dZ	ee
   ed<    ee      Zee   ed<   dZee
   ed<   d	ed
e
fdZd	ed
eeef   fdZd	ededed
eeef   fdZy)EmptyLineTrackera{  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_liner  r,   previous_defssemantic_leading_commentcurrent_liner7   c                 r   |j                   dk(  xr2 t        |j                        xr d|j                  d   j                  v }| j	                  |      \  }}| j
                  r| j
                  j                  nd}t        d||z
        }| j
                  r|| j
                  j
                  ft        | j
                  j                  j                        dk(  r:| j
                  j                  j                  r|j                  s|j                  sd}t        | j                  | j
                  ||||      }|j                  rP| j                   <| j                   j"                  sC| j                   j                  r|r+| j$                  |r|| _        n|j"                  r|rd| _        || _        || _        |S )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
NrT   )r*   r  r  r  r  r  )r+   r=   r.   rB   _maybe_empty_linesr  r  maxrU   r  r   r_   ro   r  r*   rP   r  rY   r  )rI   r  r  r  r  previous_afterblocks          rK   maybe_empty_linesz"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))#rL   c                    d}|j                   dk(  r| j                  j                  rdnd}|j                  r>|j                  d   }|j                  j                  d      }t        ||      }d|_        nd}t        |      }|j                   }d }| j                  r_| j                  d   j                   |k\  rC| j                  j                         }| j                  r| j                  d   j                   |k\  rC|j                  s|j                  r| j                  j                  |       | j                  y|j                  rD| j                  j                  ry| j                  j                  r| j                  j                  ry|| j                  J | j                  j                  rN|j                  r|j                   sd}n|r)|j                  s| j                  j                  r|rdnd}ne|rd}n`d}n]|rd}nX|sT|j                   rH|j                  d   j"                  t$        j&                  k(  r|j                  d   j(                  d	vrd}nd}|j*                  s|j                  s|j                  r| j-                  |||      S | j                  j.                  rQ| j                  j                   dk(  r8|j                   dk(  r)|j.                  st0        j2                  | j                  v ry
| j                  j.                  rC|j.                  s7|j5                  t.              s!|| j                  j                   k(  r|xs ddfS |dfS )NrT   r   rv   r   r   r   r   r   r   rT   )withtryforwhileifmatch)rT   r   r   )r+   r*   is_pyir.   rB   r   minr=   r  r   ro   r_   rH   r  r   r   rh   r;   r#   r@   r>   rY   #_maybe_empty_lines_for_class_or_defr   r   always_one_newline_after_importr   )rI   r  max_allowedrm   r  user_had_newliner+   previous_defs           rK   r  z#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;;f&6 
 ((""((A-""a' **77499D (( ** 66)6T++111Ka!##qyrL   r  r/  c                    | j                   J | j                   j                  r$| j                  j                  r|j                  ryy| j                   j
                  |j
                  k  rM| j                   j                  s| j                   j                  r!| j                  j                  ry|rddfS ddfS d }| j                   j                  r| j                   j
                  |j
                  k(  rr|dk(  rm| j                  }|^|j                  R|j                  j                  j                  s2|j                  j                  j                  s|j                  dk  r|}ny| j                  j                  r	|j                  s| j                   j                  rt| j                   j
                  |j
                  k  rd}n| j                   j
                  |j
                  kD  rd}n|j                  r| j                   j                  rd}nd}n| j                   j
                  |j
                  kD  rd}nw|j                  s|j                  r2| j                   j                  s|j
                  rt        d|      }n0d}n-d}n*|j
                  rdnd}| j                   j                  r|sd}|8|j                  }|*t!        |j                  |      |j"                  z
  |_        d}|dfS )Nr#  r"  rT   r   rv   )r  rY   r*   r*  rh   r+   r_   ro   rP   r  r  r  r   r  r+  rs   r  r  )rI   r  r  r/  comment_to_add_newlinesslcnewlinesr  s           rK   r,  z4EmptyLineTracker._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 (. {rL   )r   r   r   r   r   r   r  r   r(   r  r  r   r   r  r  r   r   r   r  r=   r,  r  rL   rK   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rL   r  sequencer7   c              #   ^   K   t        |       dz
  }t        |       D ]  }||f |dz  } yw)z;Like `reversed(enumerate(sequence))` if that were possible.rT   N)rU   r   )r5  r   elements      rK   r   r     s<     MAEH% g
s   +-new_lineold_liner.   r5   c                     |D ]j  }t        |j                  |j                        }t        ||       | j	                  ||       |j                  |      D ]  }| j	                  |d        l y)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).
    rN   TN)r$   r;   r>   r   rH   r   )r8  r9  r.   r5   old_leafnew_leafcomment_leafs          rK   append_leavesr>    sk      =x~~6h)|<$33H= 	=LOOLtO<	==rL   r   )line_strliner*   r?  c                   |st        |       }t        j                  |vr1t        |      |j                  k  xr d|vxr | j                          S | j                         ryd|vrt        |      |j                  k  S |j                  d      ^}}}t        |      |j                  kD  st        |      |j                  kD  ryg }d}g }t        j                  }	t        | j                        D ]C  \  }
}|	t        j                  k(  rd}|j                  dz   t        |      kD  r|j                  d       n+|j                  dz   t        |      k  r|j                         }|1|/|j                  |j                  dz   k(  r|j                  }	|dkD  r y|j                  |	k  r|j                  t         j"                  k(  rcdg}||z  }| j$                  s|j                  dkD  r@|
t        | j                        dz
  k7  s|j&                  |vr||j                  xx   dz  cc<   |	t        j                  k7  rt)        |	|j                        }	t+        |      sl|j,                  rp|j,                  j                  t.        j0                  k(  sG|j,                  j,                  r3|j,                  j,                  j                  t.        j2                  k(  r yt        |      dkD  r y|}|}t5        |      |v s|j                  |       |j,                  *|j,                  }t5        |      |v r9F t        |      dk(  ryt7        d |D              S )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   FNrT   r   Tc              3   &   K   | ]	  }|d k(    ywr   r  )r   vals     rK   r   z'is_line_short_enough.<locals>.<genexpr>  s     *Csax*s   )line_to_stringr   multiline_string_handlingr"   line_lengthr   splitmathinfr   r.   bracket_depthrU   rH   r   r;   r#   r   r1   r   r+  r   r   r    testdictsetmakerr   all)r@  r*   r?  r   rg   lastcommasmultiline_stringmultiline_string_contextsmax_level_to_updateir4   	had_commaignore_ctxsctxs                  rK   is_line_short_enoughrW  $  s    !$'((4h4#3#33 8H$85577	
 ((*8"d&6&666nnT*OEAt$***io@P@P.P F'+*,-1XXT[[) /!4$((*'+I!!A%F3a ##a'#f+5"JJL	%$0$22d6H6H16LL '+&8&8#q= !44ekk9Q 04fK44K$$(:(:Q(>S%))T->->k-Qt))*a/*$((*"%&94;M;M"Nt${{  DII-KK&&4;;+=+=+B+BdFWFW+W ,-1#Cc(h&)005::%jj	 c(h&W/!f $%**6***rL   c                 b   | j                   }t        |      dk  ry|d   j                  t        j                  k(  r|d   j                  t        j
                  k(  rd}d}|d   }|ddd   D ]  }|j                  t        v r|j                  t        vr y|dz  }n|j                  t        j
                  k(  r|dz  }nb|j                  t        j                  k(  r1|j                  t        j
                  k(  s(|j                  t        v s y|j                  t        vr y|dkD  s|dkD  s y y)	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).
    rv   Fr   rT   r   r9   NT)	r.   rU   r;   r#   r|   re   r   r   r^   )r@  r.   
call_count	dot_countr   r4   s         rK   can_be_splitr[    s    [[F
6{Qay~~%&)..EII*E
	bz26r6N 	Dyy,,99$44 a
eii'Q	ejj(		UYY.$))?O2O "221}a!	$ rL   rhsrF  c                    | j                   }d}t        |j                        D ]i  }|r||j                  u rd}|j                  t
        k(  r|s y|r/|j                  t        v sB|j                  |j                  v s[|j                  sh|}k |j                  }|j                  sy|j                         }|j                  |      }|dkD  ry|dk(  r |t        k(  r| j                  j                  ry|t        k(  ryt!        |j                        dk\  sJ d       |j                  d   }|j                  d   }	|j                  t"        v r!|	j                  t        vrt%        |||      ry|j                  d	   }
|j                  d
   }|j                  t&        j(                  k(  sm|j                  t&        j*                  k(  sP|j                  t&        j,                  k(  ra|j.                  rU|j.                  j                  t0        j2                  k7  r.|
j                  t"        v ryt5        |      ryt7        |||      ryy)a  Does `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.
    NFTrT   rv   zStranded delimiterr   )r   rF  r9   r   )rN  rF  )r  r   r.   r   r;   r   r   r>   r0   
delimitersmax_delimiter_prioritydelimiter_count_with_priorityr   r  r   r   rU   r   _can_omit_opening_parenr#   rz   r   r   r   r    r   r   _can_omit_closing_paren)r\  rF  r@  r	  r4   btmax_prioritydelimiter_countr   secondpenultimaterN  s               rK   can_omit_invisible_parensrh    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"4u+N ++b/K;;r?D 			UZZ99$ II#  DLL0 //u% "4dLrL   r   c                    d}d| j                   z  }d}| j                         D ]L  \  }}}|j                  t        v r|j                  |u rd}|s,||z  }||kD  r y|j                  t
        v sKd}N t        | j                        |dz   k(  ryy) See `can_omit_invisible_parens`.Fru   r   TrT   )r+   r   r;   r   r   r   rU   r.   )r@  r   rF  	remainderr   _indexr4   leaf_lengths           rK   ra  ra  
  s    I^FF%)%?%?%A !k99((T-A-AU-JIk!F#  yy,,!	 t{{vz)rL   rN  c                    d| j                   z  }d}| j                         D ]8  \  }}}||z  }||j                  u r
|s||k  s" y|j                  t        v s7d}: y)rj  ru   FT)r+   r   r   r;   r   )r@  rN  rF  r   seen_other_bracketsrl  r4   rm  s           rK   rb  rb  #  sq    ^F%)%?%?%A '!k+4'''"f&;YY**"&' rL   c                 6    t        |       j                  d      S )zmReturns the string representation of @line.

    WARNING: This is known to be computationally expensive.
    r   )r   r?   )r@  s    rK   rD  rD  4  s    
 t9??4  rL   r   )Cr   rH  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  r  r  r   r   r   r=   r>  r   rW  r[  rh  ra  rb  rD  r  rL   rK   <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 "! !# !rL   