
    `N`                         d Z ddlmZ ddlmZ ddlmZ ddlmZ dZdZdZ e	h d	          Z
d
 Z G d dej                  Zd Zd Zd ZdS )a;  Calculate the number of blank lines between top-level entities.

Calculates how many blank lines we need between classes, functions, and other
entities at the same level.

  CalculateBlankLines(): the main function exported by this module.

Annotations:
  newlines: The number of newlines required before the node.
    )	py3compat)pytree_utils)pytree_visitor)style         >   if_stmtdel_stmtfor_stmttry_stmt	exec_stmt	expr_stmt	pass_stmt	with_stmt
async_stmt
break_stmt
print_stmt
raise_stmt
small_stmt
while_stmt
yield_stmtassert_stmtglobal_stmtimport_stmtreturn_stmtsimple_stmtcontinue_stmtnonlocal_stmtc                 L    t                      }|                    |            dS )zRun the blank line calculator visitor over the tree.

  This modifies the tree in place.

  Arguments:
    tree: the top-level pytree node to annotate with subtypes.
  N)_BlankLineCalculatorVisit)treeblank_line_calculators     Blib/python3.11/site-packages/yapf/yapflib/blank_line_calculator.pyCalculateBlankLinesr&   +   s*     /00d#####    c                   R     e Zd ZdZd Zd Zd Zd Zd Z fdZ	d Z
d	 Zd
 Z xZS )r!   zB_BlankLineCalculator - see file-level docstring for a description.c                 L    d| _         d| _        d| _        d| _        d| _        d S )Nr   F)class_levelfunction_levellast_comment_linenolast_was_decoratorlast_was_class_or_function)selfs    r%   __init__z_BlankLineCalculator.__init__:   s0    DD D#D&+D###r'   c                     |                      |           t          j        |j        d                   dk    r|j        d         j        | _        d S d S )Nr   COMMENT)DefaultNodeVisitr   NodeNamechildrenlinenor,   r/   nodes     r%   Visit_simple_stmtz&_BlankLineCalculator.Visit_simple_stmtA   sS    $T]1-..);;!%q!1!8d <;r'   c                 :   | j         r?| j         |j        d         j        dz
  k    r!t          |j        d         t                     n.t          |j        d         |                     |                     |j        D ]}|                     |           d| _        d S )Nr   r   T)r,   r5   r6   _SetNumNewlines_NO_BLANK_LINES_GetNumNewlinesr"   r-   )r/   r8   childs      r%   Visit_decoratorz$_BlankLineCalculator.Visit_decoratorF   s      D DM!$4$;a$???dmA&8888dmA&(<(<T(B(BCCC  
jj"Dr'   c                     d| _         |                     |          }d| _        | xj        dz  c_        |j        |d          D ]}|                     |           | xj        dz  c_        d| _         d S )NFr   T)r.   (_SetBlankLinesBetweenCommentAndClassFuncr-   r*   r5   r"   r/   r8   indexr>   s       r%   Visit_classdefz#_BlankLineCalculator.Visit_classdefP   s    &+D#99$??E#Duvv&  
jj&*D###r'   c                    d| _         |                     |          }t          |          r;|                     |j        j                  }t          |j        d         d            n|                     |          }d| _        | xj        dz  c_        |j        |d          D ]}| 	                    |           | xj        dz  c_        d| _         d S )NFr   r   T)
r.   rA   _AsyncFunctionprev_siblingparentr;   r5   r-   r+   r"   rB   s       r%   Visit_funcdefz"_BlankLineCalculator.Visit_funcdefZ   s    &+D#99$??Ed B;;


"$ $edmA&----;;DAAe#D1uvv&  
jj1&*D###r'   c                    | j         rRt          j        |          t          v r7t          j        |          }t          ||                     |                     d| _         t          t          |           	                    |           dS )zOverride the default visitor for Node.

    This will set the blank lines required if the last entity was a class or
    function.

    Arguments:
      node: (pytree.Node) The node to visit.
    FN)
r.   r   r4   _PYTHON_STATEMENTSFirstLeafNoder;   r=   superr!   r3   )r/   r8   leaf	__class__s      r%   r3   z%_BlankLineCalculator.DefaultNodeVisitj   s     & :		t	$	$(:	:	:)$//d22488999&+D#	
%%66t<<<<<r'   c                    d}t          j        |j        |                   r|                     |j        |         j        d                    | j        s+t          |j        |         j        d         t                     |dz  }t          j        |j        |                   |rX|j        |         j        dz
  |j        |dz
           j        d         j        k    r!t          |j        |         t                     nV| j	        dz   |j        |         j        k    rt          }n| 
                    |          }t          |j        |         |           |S )aL  Set the number of blanks between a comment and class or func definition.

    Class and function definitions have leading comments as children of the
    classdef and functdef nodes.

    Arguments:
      node: (pytree.Node) The classdef or funcdef node.

    Returns:
      The index of the first child past the comment nodes.
    r   r   )r   IsCommentStatementr5   r"   r-   r;   _ONE_BLANK_LINEr6   r<   r,   r=   )r/   r8   rC   num_newliness       r%   rA   z=_BlankLineCalculator._SetBlankLinesBetweenCommentAndClassFuncz   sA    E

)$-*>
?
?  jju%.q1222$ Ke,5a8/JJJqje 
)$-*>
?
?  	 :$-&-1=#,Q/67 7dmE*O<<<<		!A	%u)=)D	D	D&++D11dmE*L999Lr'   c                     | j         rt          S |                     |          rdt          j        d          z   S t
          S )Nr   'BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION)r-   r<   _IsTopLevelr   GetrR   r7   s     r%   r=   z$_BlankLineCalculator._GetNumNewlines   sG     F			$		 FDEEEEr'   c                 >    | j         p| j         ot          |          S N)r*   r+   _StartsInZerothColumnr7   s     r%   rV   z _BlankLineCalculator._IsTopLevel   s(    !8T%89 (!$'')r'   )__name__
__module____qualname____doc__r0   r9   r?   rD   rI   r3   rA   r=   rV   __classcell__)rO   s   @r%   r!   r!   7   s        JJ, , ,9 9 9
# # #+ + ++ + + = = = = =   >  ) ) ) ) ) ) )r'   r!   c                 P    t          j        | t           j        j        |           d S rY   )r   SetNodeAnnotation
AnnotationNEWLINES)r8   rS   s     r%   r;   r;      s.     |'>'G!-/ / / / /r'   c                 z    t          j        |           j        dk    pt          |           o| j        j        dk    S )Nr   )r   rL   columnrF   rG   r8   s    r%   rZ   rZ      s?    

$T
*
*
1Q
6 C$AD$5$<$ADr'   c                 b    t           j        o#| j        ot          j        | j                  dk    S )NASYNC)r   PY3rG   r   r4   rf   s    r%   rF   rF      s1    
- >D- >

 1
2
2g
=?r'   N)r^   yapf.yapflibr   r   r   r   r<   rR   _TWO_BLANK_LINES	frozensetrK   r&   PyTreeVisitorr!   r;   rZ   rF    r'   r%   <module>ro      s	  	 	 # " " " " " % % % % % % ' ' ' ' ' '       Y         	$ 	$ 	$k) k) k) k) k)>7 k) k) k)\/ / /
D D D
? ? ? ? ?r'   