
    \Og`8                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSK	Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  Sr\R,                  " \5      r " S S\R2                  5      r " S S\R2                  5      r " S S\R2                  5      r      SS jr          SS jr " S S5      r " S S5      r  " S S5      r!g)z0Implementation of the StyleGuide used by Flake8.    )annotationsN)	Generator)Sequence)defaults)
statistics)utils)base)	Violation)
StyleGuidec                       \ rS rSrSrSrSrSrg)Selected   z<Enum representing an explicitly or implicitly selected code.zexplicitly selectedzimplicitly selected N__name__
__module____qualname____firstlineno____doc__
Explicitly
Implicitly__static_attributes__r       W/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/flake8/style_guide.pyr   r      s    F&J&Jr   r   c                       \ rS rSrSrSrSrSrg)Ignored   z;Enum representing an explicitly or implicitly ignored code.zexplicitly ignoredzimplicitly ignoredr   Nr   r   r   r   r   r      s    E%J%Jr   r   c                       \ rS rSrSrSrSrSrg)Decision&   z?Enum representing whether a code should be ignored or selected.zignored errorzselected errorr   N)r   r   r   r   r   r   r   r   r   r   r   r   r   &   s    IGHr   r   c                X    / U =(       d    / QU=(       d    / Qn[        [        USS95      $ NT)reversetuplesorted)optionextendrets      r   _explicitly_chosenr*   -   s-    
 -V\r
,fl
,CT*++r   c                p    U b  / U QU=(       d    / QnO/ UQUQU=(       d    / Qn[        [        USS95      $ r"   r$   )r'   defaultextended_defaultr(   r)   s        r   _select_ignorer.   6   sH     ((&,B(<<*<fl<T*++r   c                  J    \ rS rSrSrS
S jrSS jrSS jrSS jrSS jr	Sr
g	)DecisionEngineE   zA class for managing the decision process around violations.

This contains the logic for whether a violation should be reported or
ignored.
c                v   0 U l         [        UR                  UR                  S9U l        [        UR
                  UR                  S9U l        [        UR                  SUR                  UR                  S9U l
        [        UR
                  [        R                  UR                  UR                  S9U l        g)zInitialize the engine.)r'   r(   r   )r'   r,   r-   r(   N)cacher*   selectextend_selectselected_explicitlyignoreextend_ignoreignored_explicitlyr.   extended_default_selectselectedr   IGNOREextended_default_ignoreignored)selfoptionss     r   __init__DecisionEngine.__init__L   s    *,
#5>>(($
  #5>>((#

 '>>$<<((	
 &>>OO$<<((	
r   c                    UR                  U R                  5      (       a  [        R                  $ UR                  U R                  5      (       a  [        R
                  $ [        R
                  $ )aX  Determine if the code has been selected by the user.

:param code: The code for the check that has been run.
:returns:
    Selected.Implicitly if the selected list is empty,
    Selected.Explicitly if the selected list is not empty and a match
    was found,
    Ignored.Implicitly if the selected list is not empty but no match
    was found.
)
startswithr6   r   r   r;   r   r   r?   codes     r   was_selectedDecisionEngine.was_selectedf   sP     ??43344&&&__T]]++&&&%%%r   c                    UR                  U R                  5      (       a  [        R                  $ UR                  U R                  5      (       a  [        R
                  $ [        R
                  $ )aX  Determine if the code has been ignored by the user.

:param code:
    The code for the check that has been run.
:returns:
    Selected.Implicitly if the ignored list is empty,
    Ignored.Explicitly if the ignored list is not empty and a match was
    found,
    Selected.Implicitly if the ignored list is not empty but no match
    was found.
)rD   r9   r   r   r>   r   r   rE   s     r   was_ignoredDecisionEngine.was_ignoredx   sP     ??42233%%%__T\\**%%%&&&r   c                P  ^ U R                  T5      nU R                  T5      n[        R                  STUU5        [	        U[
        5      (       a%  [	        U[
        5      (       a  [        R
                  $ [	        U[        5      (       a%  [	        U[        5      (       a  [        R                  $ U[
        R                  L a#  U[        R                  La  [        R
                  $ U[
        R                  La#  U[        R                  L a  [        R                  $ U[        R                  L a#  U[
        R                  L a  [        R                  $ U[
        R                  L a  U[        R                  L d&  U[
        R                  L a  U[        R                  L av  [        U4S jU R                   5       5      n[        U4S jU R                   5       5      n[        U5      [        U5      :  a  [        R
                  $ [        R                  $ [        ST SU SU 35      e)z-Decide if code should be ignored or selected.z#The user configured %r to be %r, %rc              3  X   >#    U  H  nTR                  U5      (       d  M  Uv   M!     g 7fNrD   .0srF   s     r   	<genexpr>/DecisionEngine.make_decision.<locals>.<genexpr>   s     I]dooa6H!!]   *	*c              3  X   >#    U  H  nTR                  U5      (       d  M  Uv   M!     g 7frN   rO   rP   s     r   rS   rT      s     H\T__Q5G!!\rU   zunreachable  )rG   rJ   LOGdebug
isinstancer   r   r   r   r   nextr;   r>   lenAssertionError)r?   rF   r;   r>   r4   r7   s    `    r   make_decisionDecisionEngine.make_decision   s   $$T*""4(		1		
 h))j(.K.K$$$'**z'7/K/K###+++w111$$$H///7---###+++8;N;N0N###+++7;M;M0M+++7;M;M0M IT]]IIFHT\\HHF6{S[((((''' <vQxj'!KLLr   c                    U R                   R                  U5      nUc5  U R                  U5      nX R                   U'   [        R	                  SX5        U$ )a  Return the decision for a specific code.

This method caches the decisions for codes to avoid retracing the same
logic over and over again. We only care about the select and ignore
rules as specified by the user in their configuration files and
command-line flags.

This method does not look at whether the specific line is being
ignored in the file itself.

:param code: The code for the check that has been run.
z"%s" will be "%s")r3   getr^   rX   rY   )r?   rF   decisions      r   decision_forDecisionEngine.decision_for   sL     ::>>$'))$/H'JJtII)4:r   )r3   r>   r9   r;   r6   N)r@   argparse.NamespacereturnNone)rF   strrf   zSelected | IgnoredrF   rh   rf   r   )r   r   r   r   r   rA   rG   rJ   r^   rc   r   r   r   r   r0   r0   E   s"    
4&$'&(MTr   r0   c                      \ rS rSrSr S
       SS jjr    SS jrSS jr\R                      SS j5       r
 S
             SS jjrS	rg)StyleGuideManager   z.Manage multiple style guides for a single run.Nc                \   Xl         X l        [        R                  " 5       U l        U=(       d    [        U5      U l        / U l        [        XU R                  US9U l	        U R                  /U R                  U5      QU l        [        R                  " SS9" U R                  5      U l        g)CInitialize our StyleGuide.

.. todo:: Add parameter documentation.
)deciderN)maxsize)r@   	formatterr   
Statisticsstatsr0   ro   style_guidesr   default_style_guidepopulate_style_guides_with	functools	lru_cache_style_guide_forstyle_guide_for)r?   r@   rq   ro   s       r   rA   StyleGuideManager.__init__   s     "**,
9."9.0#-

G$
  $$
,,W5

  )224@!! 
r   c              #     #    [         R                  " UR                  5      nU H   u  p4U R                  R	                  X4S9v   M"     g7f)zGenerate style guides from the per-file-ignores option.

:param options:
    The original options parsed from the CLI and config file.
:returns:
    A copy of the default style guide with overridden values.
)filenameextend_ignore_withN)r   parse_files_to_codes_mappingper_file_ignoresru   copy)r?   r@   per_filer}   
violationss        r   rv   ,StyleGuideManager.populate_style_guides_with   sK      55g6N6NO$, H**//! 0   %-s   AA
c                B   ^ [        U4S jU R                   5       S S9$ )z3Find the StyleGuide for the filename in particular.c              3  V   >#    U  H  oR                  T5      (       d  M  Uv   M      g 7frN   )
applies_to)rQ   gr}   s     r   rS   5StyleGuideManager._style_guide_for.<locals>.<genexpr>   s     D)1\\(-CQQ)s   )	)c                >    [        U R                  =(       d    S5      $ )N )r\   r}   )r   s    r   <lambda>4StyleGuideManager._style_guide_for.<locals>.<lambda>   s    #ajj.B/r   )key)maxrt   r?   r}   s    `r   ry   "StyleGuideManager._style_guide_for   s!    D))D/
 	
r   c              #     #    U R                  U5      nUR                  U5         Uv   SSS5        g! , (       d  f       g= f7fz9Record the fact that we're processing the file's results.N)rz   processing_file)r?   r}   guides      r   r   !StyleGuideManager.processing_file   s5     
 $$X.""8,K -,,s   #A3	A
AAc                J    U R                  U5      nUR                  XX4XV5      $ )n  Handle an error reported by a check.

:param code:
    The error code found, e.g., E123.
:param filename:
    The file in which the error was found.
:param line_number:
    The line number (where counting starts at 1) at which the error
    occurs.
:param column_number:
    The column number (where counting starts at 1) at which the error
    occurs.
:param text:
    The text of the error message.
:param physical_line:
    The actual physical line causing the error.
:returns:
    1 if the error was reported. 0 if it was ignored. This is to allow
    for counting of the number of errors found that were not ignored.
)rz   handle_error)r?   rF   r}   line_numbercolumn_numbertextphysical_liner   s           r   r   StyleGuideManager.handle_error  s.    : $$X.!!K
 	
r   )ro   ru   rq   r@   rs   rz   rt   rN   )r@   re   rq   base_formatter.BaseFormatterro   DecisionEngine | Nonerf   rg   )r@   re   rf   !Generator[StyleGuide, None, None])r}   rh   rf   r   r}   rh   rf   r   rF   rh   r}   rh   r   intr   r   r   rh   r   
str | Nonerf   r   )r   r   r   r   r   rA   rv   ry   
contextlibcontextmanagerr   r   r   r   r   r   rk   rk      s    8 *.	
#
 0
 '	

 

6)	* 
 	*  %) 
 
  
 	 

  
  
 " 
 
 
  
r   rk   c                      \ rS rSrSr  S         SS jjrSS jr  S     SS jjr\R                      SS j5       r
SS jrSS	 jr S             SS
 jjrSrg)r   i+  z#Manage a Flake8 user's style guide.Nc                    Xl         X l        X0l        U=(       d    [        U5      U l        X@l        U R
                  (       a&  [        R                  " U R
                  5      U l        gg)rn   N)r@   rq   rs   r0   ro   r}   r   normalize_path)r?   r@   rq   rs   r}   ro   s         r   rA   StyleGuide.__init__.  sK     "
9."9 ==!00?DM r   c                "    SU R                    S3$ )z5Make it easier to debug which StyleGuide we're using.z<StyleGuide [z]>r}   )r?   s    r   __repr__StyleGuide.__repr__B  s    t}}oR00r   c                &   U=(       d    U R                   n[        R                  " U R                  5      nUR                  =(       d    / Ul        UR                  R                  U=(       d    / 5        [        X0R                  U R                  US9$ )z8Create a copy of this style guide with different values.r   )	r}   r   deepcopyr@   r8   r(   r   rq   rs   )r?   r}   r~   r@   s       r   r   StyleGuide.copyF  sm     ,t}}--- ' 5 5 ;$$%7%=2>^^TZZ(
 	
r   c              #     #    U R                   R                  U5        U v   U R                   R                  U5        g7fr   )rq   	beginningfinishedr   s     r   r   StyleGuide.processing_fileT  s0     
 	  *
)s   <>c                r    U R                   c  g[        R                  " UU R                   /U < S3[        S9$ )zCheck if this StyleGuide applies to the file.

:param filename:
    The name of the file with violations that we're potentially
    applying this StyleGuide to.
:returns:
    True if this applies, False otherwise
Tz! does %(whether)smatch "%(path)s")patternslog_messagelogger)r}   r   matches_filenamerX   r   s     r   r   StyleGuide.applies_to]  s>     == %%mm_("CD	
 	
r   c                8    U R                   R                  U5      $ )a\  Determine if the error code should be reported or ignored.

This method only cares about the select and ignore rules as specified
by the user in their configuration files and command-line flags.

This method does not look at whether the specific line is being
ignored in the file itself.

:param code:
    The code for the check that has been run.
)ro   rc   rE   s     r   should_report_errorStyleGuide.should_report_erroro  s     ||((..r   c                n   U R                   R                  nU(       d  Sn[        UUUUS-   UU5      nU R                  UR                  5      [
        R                  L n	UR                  U5      SL n
U	(       a>  U
(       a7  U R                  R                  U5        U R                  R                  U5        gg)r   r      F)r@   disable_noqar
   r   rF   r   r   is_inline_ignoredrq   handlers   record)r?   rF   r}   r   r   r   r   r   errorerror_is_selectedis_not_inline_ignoreds              r   r   StyleGuide.handle_error}  s    : ||00 MA
 $$UZZ0H4E4EE 	 !& 7 7 E N!6NN!!%(JJe$r   )ro   r}   rq   r@   rs   )NN)
r@   re   rq   r   rs   zstatistics.Statisticsr}   r   ro   r   )rf   rh   )r}   r   r~   zSequence[str] | Nonerf   r   r   )r}   rh   rf   boolri   rN   r   )r   r   r   r   r   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   +  s    -  $)-@#@ 0@ %	@
 @ '@(1  $37

 1
 
	
 **	** *
$/* %)22 2 	2
 2 2 "2 
2 2r   r   )r'   list[str] | Noner(   r   rf   tuple[str, ...])
r'   r   r,   r   r-   z	list[str]r(   r   rf   r   )"r   
__future__r   argparser   r   enumrw   loggingtypingr   r   flake8r   r   r   flake8.formattingr	   base_formatterflake8.violationr
   __all__	getLoggerr   rX   Enumr   r   r   r*   r.   r0   rk   r   r   r   r   <module>r      s    6 "            4 &
!'tyy '&dii & tyy  ,, , 	,,, ,  	,
 , ,B BJ^
 ^
BD Dr   