§
    ÷yIf'8  ã                  óŒ   — d dl mZ d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ dd„Z G d„ dej        ¦  «        ZdS )é    )ÚannotationsN)ÚbasesÚnodesÚutil)Úcheckers)Úutils)ÚHIGHÚ	INFERENCEÚnodeústr | nodes.NodeNGÚreturnÚboolc                ó^   — t          | t          j        ¦  «        o| j        dk    o| j        duS )Nr   F)Ú
isinstanceÚastroidÚConstÚvalue©r   s    úk/var/www/piapp/venv/lib/python3.11/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.pyÚ_is_constant_zeror      s0   € õ 	�4�œÑ'Ô'ÐW¨D¬J¸!ªOÐWÀÄ
ÐRWÐ@Wðó    c            	      óN  — e Zd ZdZdZdddddgifdd	d
dddgdœfdddddgdœfdœZdZh d£Z ej	        d¦  «        d2d„¦   «         Z
ed3d„¦   «         Z ej	        d¦  «        d4d „¦   «         Z ej	        d!d
d¦  «        d5d#„¦   «         Zd5d$„Zd5d%„Zd6d(„Zd7d-„Zed8d0„¦   «         Zd1S )9ÚImplicitBooleanessCheckeraö  Checks for incorrect usage of comparisons or len() inside conditions.

    Incorrect usage of len()
    Pep8 states:
    For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

        Yes: if not seq:
             if seq:

        No: if len(seq):
            if not len(seq):

    Problems detected:
    * if len(sequence):
    * if not len(sequence):
    * elif len(sequence):
    * elif not len(sequence):
    * while len(sequence):
    * while not len(sequence):
    * assert len(sequence):
    * assert not len(sequence):
    * bool(len(sequence))

    Incorrect usage of empty literal sequences; (), [], {},

    For empty sequences, (dicts, lists, tuples), use the fact that empty sequences are false.

        Yes: if variable:
             if not variable

        No: if variable == empty_literal:
            if variable != empty_literal:

    Problems detected:
    * comparison such as variable == empty_literal:
    * comparison such as variable != empty_literal:
    ÚrefactoringzQDo not use `len(SEQUENCE)` without comparison to determine if a sequence is emptyúuse-implicit-booleaness-not-lenz­Empty sequences are considered false in a boolean context. You can either remove the call to 'len' (``if not x``) or compare the length against a scalar (``if len(x) > 1``).Ú	old_names)ÚC1801zlen-as-condition)zV"%s" can be simplified to "%s", if it is strictly a sequence, as an empty %s is falseyú&use-implicit-booleaness-not-comparisona*  Empty sequences are considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not a sequence (for example ``None``, an empty string, or ``0``) the code will not be equivalent.zX"%s" can be simplified to "%s", if it is striclty a string, as an empty string is falseyú0use-implicit-booleaness-not-comparison-to-stringa'  Empty string are considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not a string (for example ``None``, an empty sequence, or ``0``) the code will not be equivalent.F)ÚC1901zcompare-to-empty-string)Údefault_enabledr   zH"%s" can be simplified to "%s", if it is strictly an int, as 0 is falseyú.use-implicit-booleaness-not-comparison-to-zeroa#  0 is considered false in a boolean context. Following this check blindly in weakly typed code base can create hard to debug issues. If the value can be something else that is falsey but not an int (for example ``None``, an empty string, or an empty sequence) the code will not be equivalent.)ÚC2001zcompare-to-zero)ÚC1802ÚC1803ÚC1804ÚC1805© >   Úisú!=ú==úis notr   ú
nodes.Callr   ÚNonec                ó  ‡— t          j        |d¦  «        sd S |j        }t          |t          j        ¦  «        r!|j        }t          |t          j        ¦  «        °!t          j        ||¦  «        sd S |j        d         }t          j        t          j	        t          j
        t          j        f}t          ||¦  «        r|                      d|t          ¬¦  «         d S 	 t          |                     ¦   «         ¦  «        }n# t           j        $ r Y d S w xY w|                      |¦  «        Št'          ˆfd„dD ¦   «         ¦  «        }d‰v s|r4|                      |¦  «        s!|                      d|t*          ¬¦  «         d S d S d S )NÚlenr   r   ©r   Ú
confidencec              3  ó    •K  — | ]}|‰v V — Œ	d S ©Nr(   ©Ú.0ÚtÚmother_classess     €r   ú	<genexpr>z7ImplicitBooleanessChecker.visit_call.<locals>.<genexpr>”   s9   øè è € ð 
ð 
Ø$%ˆA�Ðð
ð 
ð 
ð 
ð 
ð 
r   )ÚstrÚtupleÚlistÚsetÚrange)r   Úis_call_of_nameÚparentr   r   ÚBoolOpÚis_test_conditionÚargsÚListCompÚSetCompÚDictCompÚGeneratorExpÚadd_messager	   ÚnextÚinferr   ÚInferenceErrorÚbase_names_of_instanceÚanyÚinstance_has_boolr
   )Úselfr   r@   Úlen_argÚgenerator_or_comprehensionÚinstanceÚaffected_by_pep8r8   s          @r   Ú
visit_callz$ImplicitBooleanessChecker.visit_callo   sÖ  ø€ õ
 Ô$ T¨5Ñ1Ô1ð 	ØˆFð ”ˆÝ˜¥¤Ñ.Ô.ð 	#Ø”]ˆFõ ˜¥¤Ñ.Ô.ð 	#õ Ô& t¨VÑ4Ô4ð 	ØˆFØ”)˜A”,ˆåŒNÝŒMÝŒNÝÔð	&
Ð"õ �gÐ9Ñ:Ô:ð 	à×ÒØ1ØÝð ñ ô ð ð
 ˆFð	Ý˜GŸMšM™OœOÑ,Ô,ˆHˆHøÝÔ%ð 	ð 	ð 	àˆFˆFð	øøøð ×4Ò4°XÑ>Ô>ˆÝð 
ð 
ð 
ð 
Ø)Hð
ñ 
ô 
ñ 
ô 
Ðð �nÐ$Ð$Øð %Ø%)×%;Ò%;¸HÑ%EÔ%Eð %ð ×ÒØ1ØÝ$ð ñ ô ð ð ð ð %Ð$Ð$Ð$s   Ã!C? Ã?DÄDÚ	class_defúnodes.ClassDefr   c                ó`   — 	 |                       d¦  «         dS # t          j        $ r Y nw xY wdS )NÚ__bool__TF)Úgetattrr   ÚAttributeInferenceError)rU   s    r   rN   z+ImplicitBooleanessChecker.instance_has_bool    sH   € ð	Ø×Ò˜jÑ)Ô)Ð)Ø�4øÝÔ.ð 	ð 	ð 	ØˆCð	øøøàˆus   ‚ ™+ª+únodes.UnaryOpc                óÊ   — t          |t          j        ¦  «        rD|j        dk    r;t	          j        |j        d¦  «        r#|                      d|t          ¬¦  «         dS dS dS dS )z¢`not len(S)` must become `not S` regardless if the parent block is a test
        condition or something else (boolean expression) e.g. `if not len(S):`.
        Únotr0   r   r1   N)	r   r   ÚUnaryOpÚopr   r?   ÚoperandrH   r	   ©rO   r   s     r   Úvisit_unaryopz'ImplicitBooleanessChecker.visit_unaryop©   s‚   € õ �t�Uœ]Ñ+Ô+ð	à”˜5Ò Ð ÝÔ% d¤l°EÑ:Ô:ð !ð ×ÒØ1¸Íð ñ ô ð ð ð ð	ð 	à Ð Ð Ð r   r   únodes.Comparec                óú   — | j                              d¦  «        r|                      |¦  «         | j                              d¦  «        s| j                              d¦  «        r|                      |¦  «         d S d S )Nr   r"   ú-use-implicit-booleaness-not-comparison-to-str)ÚlinterÚis_message_enabledÚ-_check_use_implicit_booleaness_not_comparisonÚ_check_compare_to_str_or_zerora   s     r   Úvisit_comparez'ImplicitBooleanessChecker.visit_compare·   s’   € ð Œ;×)Ò)Ð*RÑSÔSð 	EØ×>Ò>¸tÑDÔDÐDØŒ;×)Ò)Ø<ñ
ô 
ð 	5àŒ[×+Ò+Ø;ñ
ô 
ð	5ð
 ×.Ò.¨tÑ4Ô4Ð4Ð4Ð4ð	5ð 	5r   c                óü  — d|j         fg|j        ¢}t          |¦  «        }t          t	          j        |Ž ¦  «        }t          t          |¦  «        dz
  ¦  «        D �]Ÿ}||dz            }|| j        vrŒ||         }||dz            }d}	| j	         
                    d¦  «        r¨t          |¦  «        rd}	|}
nt          |¦  «        rd}	|}
|	r|                     ¦   «         › d|› d|                     ¦   «         › �}|dv r|
                     ¦   «         nd	|
                     ¦   «         › �}|                      d||f|t          ¬
¦  «         d}	| j	         
                    d¦  «        r–d}t          j        |¦  «        rd}	|                     ¦   «         }n*t          j        |¦  «        rd}	|                     ¦   «         }|	r=|dv rd	|› �n|}|                      d|                     ¦   «         |f|t          ¬
¦  «         �Œ¡d S )NÚ é   é   Fr"   Tú >   r*   r,   únot ©rC   r   r2   re   >   r)   r+   r   )ÚleftÚopsÚiterr<   Ú	itertoolsÚchainr>   r0   Ú
_operatorsrf   rg   r   Ú	as_stringrH   r	   r   Úis_empty_str_literal)rO   r   rs   Úiter_opsÚall_opsÚops_idxÚop_2Úop_1Úop_3Úerror_detectedr_   ÚoriginalÚ
suggestionÚ	node_names                 r   ri   z7ImplicitBooleanessChecker._check_compare_to_str_or_zeroÆ   so  € ð
 13°D´I¨Ð.JÀÄÐ.JˆÝ˜‘9”9ˆÝ•y”¨Ð1Ñ2Ô2ˆÝ�S ™\œ\¨AÑ-Ñ.Ô.ð 5	ñ 5	ˆGØ˜7 Q™;Ô'ˆDØ˜4œ?Ð*Ð*ØØ˜7Ô#ˆDØ˜7 Q™;Ô'ˆDØ"ˆNØŒ{×-Ò-Ø@ñô ð +õ % TÑ*Ô*ð Ø%)�NØ�B�Bå& tÑ,Ô,ð Ø%)�NØ�BØ!ð +Ø"&§.¢.Ñ"2Ô"2ÐNÐN°TÐNÐN¸D¿NºNÑ<LÔ<LÐNÐN�Hð  Ð#3Ð3Ð3ð Ÿš™œ˜à4 B§L¢L¡N¤NÐ4Ð4ð ð
 ×$Ò$ØHØ&¨
Ð3Ø!Ý#'ð	 %ñ ô ð ð &+�NØŒ{×-Ò-Ø?ñô ð ð �	åÔ-¨dÑ3Ô3ð 1Ø%)�NØ $§¢Ñ 0Ô 0�I�IåÔ/°Ñ5Ô5ð 1Ø%)�NØ $§¢Ñ 0Ô 0�IØ!ð 	à.2°lÐ.BÐ.BÐ*˜yÐ*Ð*Ð*È	ð ð ×$Ò$ØJØ"ŸnšnÑ.Ô.°
Ð;Ø!Ý#'ð	 %ñ ô ð ùða5	ð 5	r   c           	     ó8  ‡
— t          j        |j        ¦  «        pt          j        |j        ¦  «        }|j        D ]Þ\  }}t          j        |¦  «        pt          j        |¦  «        }||z  r¬|r|j        n|}|r|n|j        }t          j        |¦  «        }|€Œ_|                      |¦  «        Š
t          ˆ
fd„dD ¦   «         ¦  «        }	|	s|                      |¦  «        rŒ§|dv r3|  	                    d|  
                    |||¦  «        |t          ¬¦  «         ŒßdS )zBCheck for left side and right side of the node for empty literals.Nc              3  ó    •K  — | ]}|‰v V — Œ	d S r4   r(   r5   s     €r   r9   zZImplicitBooleanessChecker._check_use_implicit_booleaness_not_comparison.<locals>.<genexpr>  s9   øè è € ð 1ð 1Ø,-�A˜Ð'ð1ð 1ð 1ð 1ð 1ð 1r   )r;   r<   Údictr=   >   ú<=ú>=ú<ú>r*   r+   r   rq   )r   Úis_base_containerrr   Úis_empty_dict_literalrs   Ú
safe_inferrL   rM   rN   rH   Ú!_implicit_booleaness_message_argsr	   )rO   r   Úis_left_empty_literalÚoperatorÚ
comparatorÚis_right_empty_literalÚtarget_nodeÚliteral_nodeÚtarget_instanceÚis_base_comprehension_typer8   s             @r   rh   zGImplicitBooleanessChecker._check_use_implicit_booleaness_not_comparison  s�  ø€ õ !&Ô 7ØŒIñ!
ô !
ð !4åÔ(¨¬Ñ3Ô3ð 	ð
 %)¤Hð #	ð #	Ñ ˆH�jÝ%*Ô%<Øñ&ô &ð &9åÔ,¨ZÑ8Ô8ð #ð
 &Ð(=Ñ=ð à+AÐQ˜dœi˜iÀz�Ø-CÐR˜z˜zÈÌ�å"'Ô"2°;Ñ"?Ô"?�Ø"Ð*ØØ!%×!<Ò!<¸_Ñ!MÔ!M�Ý-0ð 1ð 1ð 1ð 1Ø1Qð1ñ 1ô 1ñ .ô .Ð*ð 2ð °d×6LÒ6LØ#ñ7ô 7ð ð ð ÐAÐAÐAØ×$Ò$Ø@Ø!×CÒCØ(¨(°Kñô ð "Ý#'ð %ñ ô ð øð9#	ð #	r   únodes.NodeNGr:   c                ó¨   — t           j        dt           j        dt           j        dt           j        di                     t          |¦  «        d¦  «        S )Nr<   r;   r†   r:   Úiterable)r   ÚListÚTupleÚDictr   ÚgetÚtypera   s     r   Ú_get_node_descriptionz/ImplicitBooleanessChecker._get_node_description3  s?   € åŒJ˜ÝŒK˜ÝŒJ˜ÝŒK˜ð	
÷
 Š#�d�4‰jŒj˜*Ñ
%Ô
%ð	&r   r”   r�   r“   útuple[str, str, str]c                óŽ  — |                       |¦  «        }ddddœ                     |d¦  «        }d}t          |t          j        ¦  «        r$|j        r|j                             ¦   «         › d�}n:t          |t          j        t          j        f¦  «        r|                     ¦   «         }|› d|› d|› �}|d	k    r|› nd
|› �}|||fS )zMHelper to get the right message for "use-implicit-booleaness-not-comparison".z[]z()z{})r<   r;   r†   r™   Úxz(...)ro   r*   rp   )	rŸ   r�   r   r   ÚCallÚfuncrx   Ú	AttributeÚName)	rO   r”   r�   r“   ÚdescriptionÚcollection_literalÚinstance_nameÚoriginal_comparisonr‚   s	            r   rŽ   z;ImplicitBooleanessChecker._implicit_booleaness_message_args;  sú   € ð ×0Ò0°Ñ>Ô>ˆàØØð
ð 
÷ Š#ˆk˜:Ñ
&Ô
&ð	 	ð
 ˆÝ�k¥5¤:Ñ.Ô.ð 	4°;Ô3Cð 	4Ø*Ô/×9Ò9Ñ;Ô;ÐBÐBÐBˆMˆMÝ˜¥e¤oµu´zÐ%BÑCÔCð 	4Ø'×1Ò1Ñ3Ô3ˆMØ!.ÐPÐP°ÐPÐPÐ<NÐPÐPÐØ+3°tÒ+;Ð+;˜Ð'Ð'ÐAWÈÐAWÐAWˆ
Ø" J°Ð;Ð;r   ú%util.UninferableBase | bases.Instanceú	list[str]c                óˆ   — t          | t          j        ¦  «        r'| j        gd„ |                      ¦   «         D ¦   «         z   S g S )z�Return all names inherited by a class instance or those returned by a
        function.

        The inherited names include 'object'.
        c                ó   — g | ]	}|j         ‘Œ
S r(   )Úname)r6   r¢   s     r   ú
<listcomp>zDImplicitBooleanessChecker.base_names_of_instance.<locals>.<listcomp>X  s   € Ð!CÐ!CÐ!C¨Q !¤&Ð!CÐ!CÐ!Cr   )r   r   ÚInstancer¯   Ú	ancestorsr   s    r   rL   z0ImplicitBooleanessChecker.base_names_of_instanceN  sF   € õ �d�EœNÑ+Ô+ð 	DØ”I�;Ð!CÐ!C°$·.².Ñ2BÔ2BÐ!CÑ!CÔ!CÑCÐCØˆ	r   N)r   r-   r   r.   )rU   rV   r   r   )r   r[   r   r.   )r   rc   r   r.   )r   r—   r   r:   )r”   r—   r�   r:   r“   r—   r   r    )r   r«   r   r¬   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r¯   ÚmsgsÚoptionsrw   r   Úonly_required_for_messagesrT   ÚstaticmethodrN   rb   rj   ri   rh   rŸ   rŽ   rL   r(   r   r   r   r      sã  € € € € € ð$ð $ðL €Dð `Ø-ð+ð Ð8Ð9Ð:ð
ð
ð gØ>ðð $)ØBÐCðð ð
ð WØ<ðð
 !&Ð5QÐ4RÐSÐSð	
ð?)ð )€DðV €GØ-Ð-Ð-€Jà%€UÔ%Ð&GÑHÔHð.ð .ð .ñ IÔHð.ð` ðð ð ñ „\ðð &€UÔ%Ð&GÑHÔHðð ð ñ IÔHðð &€UÔ%Ø0Ø:Ø8ñô ð
5ð 5ð 5ñô ð
5ð=ð =ð =ð =ð~,ð ,ð ,ð ,ð\&ð &ð &ð &ð<ð <ð <ð <ð& ð
ð 
ð 
ñ „\ð
ð 
ð 
r   r   )r   r   r   r   )Ú
__future__r   ru   r   r   r   r   Úpylintr   Úpylint.checkersr   Úpylint.interfacesr	   r
   r   ÚBaseCheckerr   r(   r   r   ú<module>rÀ      sÝ   ðð
 #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð à €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -ðð ð ð ð@ð @ð @ð @ð @ Ô 4ñ @ô @ð @ð @ð @r   