
    yIfW                        d Z ddlmZ ddlZddlmZ ddlmZ ddl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 ddhZ ed          ZdZd dZd!dZd"dZd#dZ G d de          ZdS )$z+Basic Error checker from the basic checker.    )annotationsN)Iterator)Any)nodes)InferenceResult)utils)_BasicChecker)	infer_all)HIGHz_py_abc.ABCMetazabc.ABCMeta)
__module__ztyping.ForwardRef
break_nodenodes.Breakreturnnodes.For | nodes.While | Nonec                    t           j        t           j        f}| j        }t	          ||          r| t          |dg           v r/|} |j        }|n#t	          ||          | t          |dg           v /|S )zReturns the loop node that holds the break node in arguments.

    Args:
        break_node (astroid.Break): the break node of interest.

    Returns:
        astroid.For or astroid.While: the loop node holding the break node.
    orelse)r   ForWhileparent
isinstancegetattr)r   
loop_nodesr   s      \/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/base/basic_error_checker.py_get_break_loop_noder      s     )U[)JF,, 
g"? ? 1 1 
> ,, 
g"? ? 1 1 M    loopnodes.For | nodes.Whileboolc                     t           j        t           j        f}t           j        t           j        f} fd                     ||          D             t          fd                     t           j        |          D                       S )zReturns true if a loop may end with a break statement.

    Args:
        loop (astroid.For, astroid.While): the loop node inspected.

    Returns:
        bool: True if the loop may end with a break statement, False otherwise.
    c                     g | ]
}|k    |S  r!   ).0_noder   s     r   
<listcomp>z%_loop_exits_early.<locals>.<listcomp><   s*     7 7 7D== 	==r   
skip_klassc              3  >   K   | ]}t          |          v|V  d S N)r   )r"   r#   inner_loop_nodess     r   	<genexpr>z$_loop_exits_early.<locals>.<genexpr>A   sC        &&.>>> 	>>>> r   )r   r   r   FunctionDefClassDefnodes_of_classanyBreak)r   r   definition_nodesr)   s   `  @r   _loop_exits_earlyr1   1   s     )U[)J)5>:7 7 7 7((@P(QQ7 7 7
     ((AQ(RR     r   nodenodes.ClassDefc                L    t          t          j        |                     dk    S )zDetermine if the given `node` has abstract methods.

    The methods should be made abstract by decorating them
    with `abc` decorators.
    r   )lenr   unimplemented_abstract_methodsr2   s    r   _has_abstract_methodsr8   H   s"     u3D99::Q>>r   nodes.FunctionDefc                    | j         rK| j         j        D ]>}t          |t          j                  r"t	          |j        dd          | j        k    r dS ?dS )zReturn True if the object is a method redefined via decorator.

    For example:
        @property
        def x(self): return self._x
        @x.setter
        def x(self, value): self._x = value
    nameNTF)
decoratorsr   r   	Attributer   exprr;   )r2   	decorators     r   redefined_by_decoratorr@   Q   s^      . 	 	I9eo66INFD99TYFFtt5r   c            	         e Zd Zi ddddddddd	d
ddddddddifdddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,ifiZdsd/Z ej        d0          dtd3            Zdud7Z ej        d8d9          dvd;            Z	 ej        d<          dwd>            Z
 ej        d?d@d0ddAdBd)          dxdD            ZeZdxdEZdxdFZ ej        dG          dydI            Z ej        dJ          dzdL            Z ej        dJ          d{dN            Z ej        dOdP          d|dR            Z ej        dO          d}dT            Z ej        dU          d~dW            Z ej        dU          ddY            Z ej        dZ          dd\            Zdd`Z ej        da          ddb            Z ej        dc          dde            ZddhZdzdiZddkZddnZddqZdrS )BasicErrorCheckerE0100)z__init__ method is a generatorinit-is-generatorz^Used when the special class method __init__ is turned into a generator by a yield in its body.E0101)zExplicit return in __init__return-in-initzIUsed when the special class method __init__ has an explicit return value.E0102)z%s already defined line %sfunction-redefinedz3Used when a function / class / method is redefined.E0103)z%r not properly in loopnot-in-loopz=Used when break or continue keywords are used outside a loop.E0104)zReturn outside functionreturn-outside-functionzEUsed when a "return" statement is found outside a function or method.E0105)zYield outside functionyield-outside-functionzDUsed when a "yield" statement is found outside a function or method.E0106z%Return with argument inside generatorzreturn-arg-in-generatorzUsed when a "return" statement with an argument is found in a generator function or method (e.g. with some "yield" statements).
maxversion)   rQ   E0107)z#Use of the non-existent %s operatornonexistent-operatorzzUsed when you attempt to use the C-style pre-increment or pre-decrement operator -- and ++, which doesn't exist in Python.E0108)z1Duplicate argument name %s in function definitionduplicate-argument-namezCDuplicate argument names in function definitions are syntax errors.E0110)z4Abstract class %r with abstract methods instantiatedabstract-class-instantiatedzeUsed when an abstract class with `abc.ABCMeta` as metaclass has abstract methods and is instantiated.W0120)zcElse clause on loop without a break statement, remove the else and de-indent all the code inside ituseless-else-on-loopzLoops should only have an else clause if they can exit early with a break statement, otherwise the statements under else should be on the same scope as the loop itself.E0112)z.More than one starred expression in assignmenttoo-many-star-expressionszhEmitted when there are more than one starred expressions (`*x`) in an assignment. This is a SyntaxError.E0113)z4Starred assignment target must be in a list or tupleinvalid-star-assignment-targetzFEmitted when a star expression is used as a starred assignment target.E0114)z4Can use starred expression only in assignment targetstar-needs-assignment-targetzCEmitted when a star expression is not used in an assignment target.E0115)zName %r is nonlocal and globalnonlocal-and-globalz0Emitted when a name is both nonlocal and global.E0116)z0'continue' not supported inside 'finally' clausecontinue-in-finallyz]Emitted when the `continue` keyword is found inside a finally clause, which is a SyntaxError.E0117)z&nonlocal name %s found without bindingnonlocal-without-bindingz^Emitted when a nonlocal variable does not have an attached name somewhere in the parent scopesE0118z+Name %r is used prior to global declarationused-prior-global-declarationzcEmitted when a name is used prior a global declaration, which results in an error since Python 3.6.
minversion)rQ      r   Nonec                >    | j         j        j        }|dk    | _        d S )N)rQ      )linterconfig
py_version
_py38_plus)selfro   s     r   openzBasicErrorChecker.open   s    ['2
$.r   rH   r2   r3   c                2    |                      d|           d S )Nclass)_check_redefinitionrq   r2   s     r   visit_classdefz BasicErrorChecker.visit_classdef   s      $/////r   assign_tuplenodes.Tupler   c                    d}|                                 D ]R}t          |t          j                  r|                     |          c S t          |t          j                  r|dz  }S|dk    S )Nr      )iteredr   r   Tuple_too_many_starred_for_tupleStarred)rq   rx   starred_countelems       r   r~   z-BasicErrorChecker._too_many_starred_for_tuple   sz     '')) 	# 	#D$,, >77=====$.. #"q  r   r[   r]   nodes.Assignc                ,   |j         d         }t          |j         d         t          j                  r|                     d|           t          |t          j                  sd S |                     |          r|                     d|           d S d S )Nr   r]   r7   r[   )targetsr   r   r   add_messager}   r~   )rq   r2   assign_targets      r   visit_assignzBasicErrorChecker.visit_assign   s    
 Qdl1ou}55 	J=DIII-55 	F++M:: 	E8tDDDDD	E 	Er   r_   nodes.Starredc                   t          |j        t          j                  rdS t          |j        t          j        t          j        t          j        t          j        f          rdS |                                }t          |t          j	                  sdS |j
        |u s|j
                            |          r|                     d|           dS dS )z@Check that a Starred expression is used in an assignment target.Nr_   r7   )r   r   r   CallListr}   SetDict	statementAssignvalue	parent_ofr   )rq   r2   stmts      r   visit_starredzBasicErrorChecker.visit_starred   s     dk5:.. 	 FdkEJUY
#STT 	F~~$-- 	F:!5!5d!;!;;$GGGGG r   rD   rF   rU   ra   r9   c                x   |                      |           |                     |           t          |          s@t          j        |          s,|                     |                                rdpd|           |                    t          j	        t          j
        t          j        f          }|                                rs|j        dk    rh|                                r|                     d|           n<d |D             }t          d |D                       r|                     d	|           i }t!          d |j        j        |j        j        g          }t&          j                            |          D ]:}|j        |v r%|                     d
||j        ft,                     0|||j        <   ;d S )Nmethodfunctionr%   __init__rD   r7   c                    g | ]	}|j         
S r!   )r   )r"   rs     r   r$   z7BasicErrorChecker.visit_functiondef.<locals>.<listcomp>  s    333a!'333r   c              3  B   K   | ]}t          j        |          |V  d S r(   )r   is_none)r"   vs     r   r*   z6BasicErrorChecker.visit_functiondef.<locals>.<genexpr>  s1      AAQa0@0@AqAAAAAAr   rF   rU   )r2   args
confidence)_check_nonlocal_and_global_check_name_used_prior_globalr@   r   (is_registered_in_singledispatch_functionru   	is_methodr-   r   Returnr+   r,   r;   is_generatorr   r.   filterr   
kwonlyargs	itertoolschainfrom_iterabler   )rq   r2   returnsvaluesarg_clusters	argumentsargs          r   visit_functiondefz#BasicErrorChecker.visit_functiondef  s    	''---**4000%
 
 	X@FF	X $$T^^%5%5%B(%PjRVWWW%%Le&7%H & 
 
 >> 	B	Z 7 7  "" B  !44 @@@@337333AA&AAAAA B$$%5D$AAA#)$AU0V#W#W	?00;; 		- 		-Cx<''  -(#	 !     *-SX&&		- 		-r   c                p   fd                     t          j                  D             }|sd S                      t          j                  D ]e}|                                ur|j        }|                    |          }|s8|j        }|r$||j        k    r|                     d||f           fd S )Nc                V    i | ]%}|j         D ]}|                                u ||&S r!   )namesscope)r"   childr;   r2   s      r   
<dictcomp>zCBasicErrorChecker._check_name_used_prior_global.<locals>.<dictcomp>/  sQ     
 
 

 
 {{}}$$ % %$$$r   rg   r2   r   )	r-   r   GlobalNamer   r;   get
fromlinenor   )rq   r2   scope_globals	node_namer;   corresponding_globalglobal_linenos    `     r   r   z/BasicErrorChecker._check_name_used_prior_global.  s    
 
 
 
,,U\::
 
 
  	F,,UZ88 	 	I  ,,>D#0#4#4T#:#: ' 0;M 1E!E!E  3)4' !   	 	r   c                   dfdt           j        j        }t           |fd                    t
          j                  D                                 }|sdS t           |fd                    t
          j                  D                                 }|                    |          D ]}| 	                    d	|f
           dS )z.Check that a name is both nonlocal and global.currentnodes.Global | nodes.Nonlocalr   r   c                0    |                                  u S r(   )r   )r   r2   s    r   
same_scopez@BasicErrorChecker._check_nonlocal_and_global.<locals>.same_scopeK  s    ==??d**r   c              3  <   K   | ]} |          |j         V  d S r(   r   r"   r   r   s     r   r*   z?BasicErrorChecker._check_nonlocal_and_global.<locals>.<genexpr>P  I        :e$$     r   Nc              3  <   K   | ]} |          |j         V  d S r(   r   r   s     r   r*   z?BasicErrorChecker._check_nonlocal_and_global.<locals>.<genexpr>[  r   r   ra   r   r2   )r   r   r   r   )
r   r   r   setr-   r   Nonlocalr   intersectionr   )rq   r2   	from_iter	nonlocalsglobal_varsr;   r   s    `    @r   r   z,BasicErrorChecker._check_nonlocal_and_globalH  s3   	+ 	+ 	+ 	+ 	+ 	+ O1	I    !00@@    
 
	  	FI    !00>>    
 
 **;77 	M 	MD2$tLLLL	M 	Mr   rL   nodes.Returnc                    t          |                                t          j                  s|                     d|           d S d S )NrL   r7   )r   framer   r+   r   rv   s     r   visit_returnzBasicErrorChecker.visit_returnd  sL    $**,,(9:: 	C6TBBBBB	C 	Cr   rN   nodes.Yieldc                0    |                      |           d S r(   _check_yield_outside_funcrv   s     r   visit_yieldzBasicErrorChecker.visit_yieldi      &&t,,,,,r   nodes.YieldFromc                0    |                      |           d S r(   r   rv   s     r   visit_yieldfromz!BasicErrorChecker.visit_yieldfromm  r   r   rJ   rc   nodes.Continuec                2    |                      |d           d S )Ncontinue_check_in_looprv   s     r   visit_continuez BasicErrorChecker.visit_continueq  s    D*-----r   r   c                2    |                      |d           d S )Nbreakr   rv   s     r   visit_breakzBasicErrorChecker.visit_breaku  s    D'*****r   rY   	nodes.Forc                0    |                      |           d S r(   _check_else_on_looprv   s     r   	visit_forzBasicErrorChecker.visit_fory        &&&&&r   nodes.Whilec                0    |                      |           d S r(   r   rv   s     r   visit_whilezBasicErrorChecker.visit_while}  r   r   rS   nodes.UnaryOpc                    |j         dv rnt          |j        t          j                  rQ|j        j         |j         k    r>|j        dz   |j        j        k    r(|                     d||j         dz             dS dS dS dS dS )z2Check use of the non-existent ++ and -- operators.z+-r{   rS      r   N)opr   operandr   UnaryOp
col_offsetr   rv   s     r   visit_unaryopzBasicErrorChecker.visit_unaryop  s     W__4<77 DG++1$(???3$TWq[QQQQQ ___++??r   nodes.Nonlocalr;   strc                   |                                 }|j        |t          |t          j        t          j        f          s|                     d|f|           d S ||                                 u s	||j        vr|j                                         }d S t          |t          j                  s!|                     d|f|t                     d S d S )Nre   r   )r   r2   r   )	r   r   r   r   r,   r+   r   localsr   )rq   r2   r;   current_scopes       r   _check_nonlocal_without_bindingz1BasicErrorChecker._check_nonlocal_without_binding  s    

".mene>O-PQQ   !;4'PT UUU
 

,,M<P0P0P - 4 : : < < F-):;; 	*$tPT      	 	r   re   c                F    |j         D ]}|                     ||           d S r(   )r   r   )rq   r2   r;   s      r   visit_nonlocalz BasicErrorChecker.visit_nonlocal  s6    J 	= 	=D00t<<<<	= 	=r   rW   
nodes.Callc                `    t          |j                  D ]}|                     ||           dS )zRCheck instantiating abstract class with
        abc.ABCMeta as metaclass.
        N)r
   func!_check_inferred_class_is_abstract)rq   r2   inferreds      r   
visit_callzBasicErrorChecker.visit_call  sD    
 "$),, 	C 	CH228TBBBB	C 	Cr   r  r   c                   t          |t          j                  sd S t          j        |          }||u rd S t          |          }|sd S |                                }|Q|                                D ]:}|                                dk    r | 	                    d|j
        f|            n;d S |                                t          v r | 	                    d|j
        f|           d S d S )Nzabc.ABCrW   r   )r   r   r,   r   node_frame_classr8   	metaclass	ancestorsqnamer   r;   ABC_METACLASSES)rq   r  r2   klassabstract_methodsr  ancestors          r   r  z3BasicErrorChecker._check_inferred_class_is_abstract  s2    (EN33 	F&t,,H
 F 1:: 	F&&((	 %..00  >>##y00$$5X]<LSW %    E	 1 F??//-X]4D4       0/r   c                    t          |                                t          j        t          j        f          s|                     d|           d S d S )NrN   r7   )r   r   r   r+   Lambdar   rv   s     r   r   z+BasicErrorChecker._check_yield_outside_func  sS    $**,,):EL(IJJ 	B5DAAAAA	B 	Br   r   c                    |j         r<t          |          s/|                     d||j         d         j        dz
             dS dS dS )z>Check that any loop with an else clause has a break statement.rY   r   r{   )r2   lineN)r   r1   r   linenorv   s     r   r   z%BasicErrorChecker._check_else_on_loop  sp    ; 	066 	& [^*Q.      	 	 	 	r   nodes.Continue | nodes.Breakr   c                   |                                 D ]}t          |t          j        t          j        f          r||j        vr dS t          |t          j        t          j        f          r n\t          |t          j                  rA||j	        v r8t          |t          j
                  r| j        s|                     d|           |                     d||           dS )z0Check that a node is inside a for or while loop.Nrc   r7   rJ   r   )node_ancestorsr   r   r   r   r   r,   r+   Try	finalbodyContinuerp   r   )rq   r2   r   r   s       r   r   z BasicErrorChecker._check_in_loop  s     ))++ 	C 	CF&59ek":;; v},,FF&5>53D"EFF 659--CF,,,tU^44 - -   !6T BBBT	BBBBBr   	redeftypenodes.Call | nodes.FunctionDefc                   |j                                         }d |j        |j                 D             }t	          d |D             |          }||urt          j        ||          st          |t          j	                  r|j        t          v rdS t          j        |          rdS t          |j         t          j                  rit          |j         j        t          j                  r_|j         j        j        dk    rJt          |j         j        j        t          j                  r!|j         j        j        j        |j        k    rdS t          |j         j        t          j                  rt          |j         j        j        t          j                  r|j         j        j        j        |j        k    rz|j         j        j        d         d         dk    rYt          |j         j        j        d         d         t          j                  r$|j         j        j        d         d         j        dS 	 |                    |          }|d|         D ]R}t          j        |          }|r:t          |t
          j                  r |                                t8          k    r dS Sn# t:          $ r Y nw xY w| j        j        j         }	|	r|	!                    |j                  rdS | "                    d|||j#        f	           dS dS dS )
z;Check for redefinition of a function / method / class name.c                h    g | ]/}t          |j        t          j                  r|j        j        -|0S r!   )r   r   r   	AnnAssignsimple)r"   is     r   r$   z9BasicErrorChecker._check_redefinition.<locals>.<listcomp>  sK     
 
 
qx99
 ?@ho

 
 
r   c              3  B   K   | ]}t          j        |          |V  d S r(   )r   is_overload_stub)r"   locals     r   r*   z8BasicErrorChecker._check_redefinition.<locals>.<genexpr>  s2      SSuU5KE5R5RSUSSSSSSr   Nnotr   isr{   rH   r   )$r   r   r   r;   nextastroidare_exclusiver   r   r,   REDEFINABLE_METHODSr   r!  Iftestr   r   r   r   CompareleftopsConstr   index
safe_inferInstancer	  TYPING_FORWARD_REF_QNAME
ValueErrorrm   rn   dummy_variables_rgxmatchr   r   )
rq   r  r2   parent_frameredefinitionsdefined_selfredefinition_indexredefinitionr  r4  s
             r   ru   z%BasicErrorChecker._check_redefinition  s    {((**
 
!(3
 
 

 SSSSS
 
 t##G,A$,U,U# <88I!444 %d++  $+ux00  t{/??(+u44"4;#3#;UZHH 5(05BBF
 t{/??"4;#3#8%*EE (-2di??(,Q/2d::"4;#3#7#:1#=u{KK ;(,Q/28@F%2%8%8%>%>" %22E3E2E$F  L$/==H &x1ABB %NN,,0HHH     #'+"4"H" ':'@'@'K'K $!89      m $###s   5J( (
J54J5N)r   rj   )r2   r3   r   rj   )rx   ry   r   r   )r2   r   r   rj   )r2   r   r   rj   )r2   r9   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r2   r   r;   r   r   rj   )r2   r   r   rj   )r2   r   r   rj   )r  r   r2   r   r   rj   )r2   r   r   rj   )r2   r  r   r   r   rj   )r  r   r2   r  r   rj   )__name__r   __qualname__msgsrr   r   only_required_for_messagesrw   r~   r   r   r   visit_asyncfunctiondefr   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   ru   r!   r   r   rB   rB   d   s3       i 
i 	 
i 	 
i$ 	 
%i. 	 
/i8 	 
9iB 	3%U6"
CiP 	 
Qi\ 	 
]if 	 
gir 	 
siB 	 
CiN 	 
OiX 	 
Yib 	 
cil 	 
mix 	 
yiD 	9+:6"
Ei iDV/ / / / &U%&:;;0 0 0 <;0! ! ! ! &U%#%E 
E 
E 
E 
E &U%&DEEH H H FEH" &U%!!' - - - -B /   4M M M M8 &U%&?@@C C C A@C &U%&>??- - - @?- &U%&>??- - - @?- &U%m5JKK. . . LK. &U%m44+ + + 54+ &U%&<==' ' ' >=' &U%&<==' ' ' >=' &U%&<==R R R >=R   , &U%&@AA= = = BA= &U%&CDDC C C EDC% % % %NB B B B
 
 
 
C C C C*J J J J J Jr   rB   )r   r   r   r   )r   r   r   r   )r2   r3   r   r   )r2   r9   r   r   )__doc__
__future__r   r   collections.abcr   typingr   r&  r   astroid.typingr   pylint.checkersr   "pylint.checkers.base.basic_checkerr	   pylint.checkers.utilsr
   pylint.interfacesr   r
  	frozensetr(  r2  r   r1   r8   r@   rB   r!   r   r   <module>rJ     sr  
 2 1 " " " " " "     $ $ $ $ $ $              * * * * * * ! ! ! ! ! ! < < < < < < + + + + + + " " " " " "$m4i00 .    *   .? ? ? ?   &a a a a a a a a a ar   