
    `N`                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d d	e	          Z
 G d
 de	          Z G d de	          ZdS )zRepresents the state of Python objects being formatted.

Objects (e.g., list comprehensions, dictionaries, etc.) have specific
requirements on how they're formatted. These state objects keep track of these
requirements.
    )absolute_import)division)print_function)format_token)	py3compat)stylec                   h    e Zd ZdZd Zd Zed             Zed             Zd Z	d Z
d Zd	 Zd
 ZdS )ComprehensionStatea  Maintains the state of list comprehension formatting decisions.

  A stack of ComprehensionState objects are kept to ensure that list
  comprehensions are wrapped with well-defined rules.

  Attributes:
    expr_token: The first token in the comprehension.
    for_token: The first 'for' token of the comprehension.
    opening_bracket: The opening bracket of the list comprehension.
    closing_bracket: The closing bracket of the list comprehension.
    has_split_at_for: Whether there is a newline immediately before the
      for_token.
    has_interior_split: Whether there is a newline within the comprehension.
      That is, a split somewhere after expr_token or before closing_bracket.
  c                 >    || _         d | _        d| _        d| _        d S NF)
expr_token	for_tokenhas_split_at_forhas_interior_split)selfr   s     9lib/python3.11/site-packages/yapf/yapflib/object_state.py__init__zComprehensionState.__init__/   s&     DODN!D#D    c                 ,    | j         j        j        dk    S )zBReturns whether the comp_expr is "trivial" i.e. is a single token.for)r   
next_tokenvaluer   s    r   HasTrivialExprz!ComprehensionState.HasTrivialExpr5   s    ?%+u44r   c                     | j         j        S N)r   previous_tokenr   s    r   opening_bracketz"ComprehensionState.opening_bracket9   s    ?))r   c                     | j         j        S r   r   matching_bracketr   s    r   closing_bracketz"ComprehensionState.closing_bracket=       00r   c                 v    t          | j                  }| j        |_        | j        |_        | j        |_        |S r   )r
   r   r   r   r   r   clones     r   ClonezComprehensionState.CloneA   s5    t//EnEO!2E#6ELr   c                 r    d| j         d| j        d| j        d| j        d|                                 dS )Nz[opening_bracket::z, for_token::z, has_split_at_for::z, has_interior_split::z, has_trivial_expr::])r   r   r   r   r   r   s    r   __repr__zComprehensionState.__repr__H   sO      !!!4>>>43H3H3H$$$d&9&9&;&;&;&;= >r   c                 B    t          |           t          |          k    S r   hashr   others     r   __eq__zComprehensionState.__eq__N       ::e$$r   c                     | |k     S r    r.   s     r   __ne__zComprehensionState.__ne__Q       u}r   c                 P    t          | j        | j        | j        | j        f          S r   )r-   r   r   r   r   r   argskwargss      r   __hash__zComprehensionState.__hash__T   s,    $.$2G(* + + +r   N)__name__
__module____qualname____doc__r   r   propertyr   r"   r'   r*   r0   r4   r:   r3   r   r   r
   r
      s          $ $ $5 5 5 * * 8* 1 1 81  > > >% % %  + + + + +r   r
   c                      e Zd ZdZd Zed             Zed             Ze ej	                    d                         Z
e ej	                    d                         Ze ej	                    d                         Z ej	                    d             Z ej	                    d	             Zd
 Zd Zd Zd Zd ZdS )ParameterListStateaH  Maintains the state of function parameter list formatting decisions.

  Attributes:
    opening_bracket: The opening bracket of the parameter list.
    closing_bracket: The closing bracket of the parameter list.
    has_typed_return: True if the function definition has a typed return.
    ends_in_comma: True if the parameter list ends in a comma.
    last_token: Returns the last token of the function declaration.
    has_default_values: True if the parameters have default values.
    has_split_before_first_param: Whether there is a newline before the first
      parameter.
    opening_column: The position of the opening parameter before a newline.
    parameters: A list of parameter objects (Parameter).
    split_before_closing_bracket: Split before the closing bracket. Sometimes
      needed if the indentation would collide.
  c                 V    || _         || _        || _        |j        | _        d| _        d S r   )r   has_split_before_first_paramopening_column
parameterssplit_before_closing_bracket)r   r   newlinerD   s       r   r   zParameterListState.__init__k   s2    *D(/D%(D%0DO(-D%%%r   c                     | j         j        S r   r    r   s    r   r"   z"ParameterListState.closing_bracketr   r#   r   c                 ,    | j         j        j        dk    S )Nz->)r"   r   r   r   s    r   has_typed_returnz#ParameterListState.has_typed_returnv   s    *0D88r   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S r   )has_default_value.0params     r   	<genexpr>z8ParameterListState.has_default_values.<locals>.<genexpr>}   s%      DD5u&DDDDDDr   )anyrE   r   s    r   has_default_valuesz%ParameterListState.has_default_valuesz   s#     DDDODDDDDDr   c                 T    | j         sdS | j         d         j        j        j        dk    S )NF,)rE   
last_tokenr   r   r   s    r   ends_in_commaz ParameterListState.ends_in_comma   s.     ? U?2)4:cAAr   c                 d    | j         j        }|j        s|j        r|j        }|j        s|j        |S r   )r   r!   
is_commentr   )r   tokens     r   rW   zParameterListState.last_token   sH      1E 5#3 e  5#3 Lr   c                     | j         sdS | j        sdS | j        j        }| j        d         j        }||j        t          |j                  z
  z  }||z   t          j        d          k    S )z8Return true if the last parameter fits on a single line.FTrU   COLUMN_LIMIT)	rJ   rE   rW   total_lengthfirst_tokenlenr   r   Getr   indentr^   
last_params       r   LastParamFitsOnLinez&ParameterListState.LastParamFitsOnLine   ss       U? T?/L$0JJ+c*2B.C.CCCL& EIn$=$===r   c                    t          j        d          rdS | j        rdS | j        sdS | j        j        }| j        d         j        }||j        t          |j                  z
  z  }||z   t          j        d          k    S )z:Return true if there's a split before the closing bracket.DEDENT_CLOSING_BRACKETSTFrU   r]   )	r   ra   rX   rE   rW   r^   r_   r`   r   rb   s       r   SplitBeforeClosingBracketz,ParameterListState.SplitBeforeClosingBracket   s     y*++ T T? U?/L$0JJ+c*2B.C.CCCL& 59^#<#<<<r   c                     t          | j        | j        | j                  }| j        |_        d | j        D             |_        |S )Nc                 6    g | ]}|                                 S r3   )r'   rN   s     r   
<listcomp>z,ParameterListState.Clone.<locals>.<listcomp>   s     CCC%CCCr   )rA   r   rC   rD   rF   rE   r%   s     r   r'   zParameterListState.Clone   sL    t3#@#24 4E *.)JE&CC4?CCCELr   c                 0    d| j         | j        | j        fz  S )NzK[opening_bracket::%s, has_split_before_first_param::%s, opening_column::%d])r   rC   rD   r   s    r   r*   zParameterListState.__repr__   s'    "!4#D "" #r   c                 B    t          |           t          |          k    S r   r,   r.   s     r   r0   zParameterListState.__eq__   r1   r   c                     | |k     S r   r3   r.   s     r   r4   zParameterListState.__ne__   r5   r   c                 d    t          | j        | j        | j        d | j        D             f          S )Nc              3   4   K   | ]}t          |          V  d S r   r,   rN   s     r   rQ   z.ParameterListState.__hash__.<locals>.<genexpr>   s(      HHutE{{HHHHHHr   )r-   r   rC   rD   rE   r7   s      r   r:   zParameterListState.__hash__   sA    		t@		HHHHH	JK K Kr   N)r;   r<   r=   r>   r   r?   r"   rJ   r   	lru_cacherS   rX   rW   re   rh   r'   r*   r0   r4   r:   r3   r   r   rA   rA   Y   s        ". . . 1 1 81 9 9 89 9E E  8E 9B B  8B
 9   8 9	> 	> 	> 9= = =  # # #% % %  K K K K Kr   rA   c                   v    e Zd ZdZd Ze ej                    d                         Zd Z	d Z
d Zd Zd Zd	S )
	Parametera  A parameter in a parameter list.

  Attributes:
    first_token: (format_token.FormatToken) First token of parameter.
    last_token: (format_token.FormatToken) Last token of parameter.
    has_default_value: (boolean) True if the parameter has a default value
  c                 "    || _         || _        d S r   r_   rW   )r   r_   rW   s      r   r   zParameter.__init__   s    "D DOOOr   c                     | j         }|| j        k    rHt          j        j        |j        v rdS |                                r|j        }n|j        }|| j        k    HdS )z2Returns true if the parameter has a default value.TF)	r_   rW   r   SubtypeDEFAULT_OR_NAMED_ASSIGNsubtypes
OpensScoper!   r   )r   toks     r   rM   zParameter.has_default_value   sj     
C

 
 			5	E	Et			 "n 
 
  5r   c                 6    t          | j        | j                  S r   )rs   r_   rW   r   s    r   r'   zParameter.Clone   s    T%t777r   c                 (    d| j         d| j        dS )Nz[first_token::z, last_token:r)   ru   r   s    r   r*   zParameter.__repr__   s%     151A1A1A15B Br   c                 B    t          |           t          |          k    S r   r,   r.   s     r   r0   zParameter.__eq__   r1   r   c                     | |k     S r   r3   r.   s     r   r4   zParameter.__ne__   r5   r   c                 8    t          | j        | j        f          S r   )r-   r_   rW   r7   s      r   r:   zParameter.__hash__   s    !4?3444r   N)r;   r<   r=   r>   r   r?   r   rq   rM   r'   r*   r0   r4   r:   r3   r   r   rs   rs      s         ! ! ! 9
 
  8
8 8 8B B B% % %  5 5 5 5 5r   rs   N)r>   
__future__r   r   r   yapf.yapflibr   r   r   objectr
   rA   rs   r3   r   r   <module>r      s    ' & & & & &       % % % % % % % % % % % % " " " " " "      8+ 8+ 8+ 8+ 8+ 8+ 8+ 8+vfK fK fK fK fK fK fK fKR)5 )5 )5 )5 )5 )5 )5 )5 )5 )5r   