
    yIf                        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
mZ ddlmZ erddlmZ ddZddZ G d de
          ZddZdS )z#Dataclass checkers for Python code.    )annotations)TYPE_CHECKING)nodes)DATACLASS_MODULES)BaseCheckerutils)	INFERENCE)PyLinternodenodes.Modulereturnboolc                    | j         t          v S )z=Utility function to check if node is from dataclasses_module.)namer   )r   s    U/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/dataclass_checker.py_is_dataclasses_moduler      s    9)))    nodes.Name | nodes.Attribute
check_withstrc                    t          | t          j                  rt          | j                  |k    S t          | j                  |k    S )zdUtility function to check either a Name/Attribute node's name/attrname with a
    given string.
    )
isinstancer   Namer   r   attrname)r   r   s     r   _check_name_or_attrname_eq_tor      s@     $
## ,49~~++t}++r   c                  b    e Zd ZdZdZddiZ ej        d          dd
            ZddZ	ddZ
dS )DataclassCheckerzoChecker that detects invalid or problematic usage in dataclasses.

    Checks for
    * invalid-field-call
    	dataclassE3701)zInvalid usage of field(), %sinvalid-field-callzThe dataclasses.field() specifier should only be used as the value of an assignment within a dataclass, or within the make_dataclass() function.r    r   
nodes.Callr   Nonec                0    |                      |           d S N)_check_invalid_field_call)selfr   s     r   
visit_callzDataclassChecker.visit_call6   s    &&t,,,,,r   c                J   t          |j        t          j        t          j        f          sdS t          |j        d          sdS t          j        |j                  }t          |t          j                  r!t          |
                                          sdS |j        }|rUt          |t          j        t          j        f          s/|j        }|r&t          |t          j        t          j        f          /t          |t          j                  r|                     ||           dS |r|j        s |                     d|dt"                     dS t          |j        t          j                  r||j        j        k    s |                     d|dt"                     dS dS )af  Checks for correct usage of the dataclasses.field() specifier in
        dataclasses or within the make_dataclass() function.

        Emits message
        when field() is detected to be used outside a class decorated with
        @dataclass decorator and outside make_dataclass() function, or when it
        is used improperly within a dataclass.
        Nfieldr    zFit should be used within a dataclass or the make_dataclass() function.r   args
confidence)z;it should be the value of an assignment within a dataclass.)r   funcr   r   	Attributer   r   
safe_inferFunctionDefr   rootparentClassDefCall%_check_invalid_field_call_within_callis_dataclassadd_messager	   	AnnAssignvalue)r&   r   inferred_func
scope_nodes       r   r%   z*DataclassChecker._check_invalid_field_call:   s    $)ej%/%BCC 	F,TY@@ 	F(33}e&788	&}'9'9';';<<	 F[
 	+J8T!U!U 	+#*J  	+J8T!U!U 	+ j%*-- 	66tZHHHF 		!8 		$ %     F4;88 	TT[EV=V=V$U$	       >W=Vr   r<   c                d   t          j        |j                  }t          |j        t          j        t          j        f          rM|j        j        dk    r=t          |t          j                  r#t          |
                                          rdS |                     d|dt                     dS )zvChecks for special case where calling field is valid as an argument of the
        make_dataclass() function.
        make_dataclassNr    r*   r+   )r   r0   r.   r   r   r   
AssignNamer   r1   r   r2   r8   r	   )r&   r   r<   r;   s       r   r6   z6DataclassChecker._check_invalid_field_call_within_callh   s     (99zU5E(FGG	$(888=%*;<< 9&}'9'9';';<< 9 F  ! 	 	
 	
 	
 	
 	
r   N)r   r!   r   r"   )r   r!   r<   r!   r   r"   )__name__
__module____qualname____doc__r   msgsr   only_required_for_messagesr'   r%   r6    r   r   r   r   %   s          D 
D &U%&:;;- - - <;-, , , ,\
 
 
 
 
 
r   r   linterr
   r"   c                J    |                      t          |                      d S r$   )register_checkerr   )rG   s    r   registerrJ      s%    
,V4455555r   N)r   r   r   r   )r   r   r   r   r   r   )rG   r
   r   r"   )rC   
__future__r   typingr   astroidr   astroid.brain.brain_dataclassesr   pylint.checkersr   r   pylint.interfacesr	   pylint.lintr
   r   r   r   rJ   rF   r   r   <module>rR      s  
 * ) " " " " " "                   = = = = = = . . . . . . . . ' ' ' ' ' ' %$$$$$$* * * *
, , , ,X
 X
 X
 X
 X
{ X
 X
 X
v6 6 6 6 6 6r   