Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pylint/checkers/refactoring/__pycache__/implicit_booleaness_checker.cpython-39.pyc
Ðазад
a n�h�5 � @ s~ d dl mZ d dlZd dlZd dlmZmZmZ d dlmZ d dl m Z d dlmZm Z ddd �d d�ZG dd � d ej�ZdS )� )�annotationsN)�bases�nodes�util)�checkers)�utils)�HIGH� INFERENCEzstr | nodes.NodeNG�bool��node�returnc C s t | tj�o| jdko| jduS )Nr F)� isinstance�astroid�Const�value�r � r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/pylint/checkers/refactoring/implicit_booleaness_checker.py�_is_constant_zero s �r c @ s e Zd ZdZdZdddddgifdd d ddd gd�fdddddgd�fd�ZdZh d�Ze� d�ddd�dd��Z eddd�dd��Ze� d�d dd�d!d"��Z e� d#d d�d$dd�d%d&��Zd$dd�d'd(�Zd$dd�d)d*�Zd+d,d�d-d.�Zd+d,d+d/d0�d1d2�Zed3d4d�d5d6��Zd7S )8�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: ZrefactoringzQDo 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)ZC1801zlen-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 strictly 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)ZC1901zcompare-to-empty-string)Zdefault_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.)ZC2001zcompare-to-zero)ZC1802ZC1803ZC1804ZC1805r > �is not�==�is�!=z nodes.Call�Noner c s� t �|d�sd S |j}t|tj�r*|j}qt �||�s:d S |jd }t|tjtj tj f�rn| jd|td� d S zt |�� �}W n tjy� Y d S 0 | �|�� t� fdd�dD ��}d� v s�|r�| �|�s�| jd|td� d S ) N�lenr r �r � confidencec 3 s | ]}|� v V qd S �Nr ��.0�t�Zmother_classesr r � <genexpr>� s z7ImplicitBooleanessChecker.visit_call.<locals>.<genexpr>)�str�tuple�list�set�range)r �is_call_of_name�parentr r �BoolOpZis_test_condition�args�ListComp�SetComp�DictComp�add_messager �nextZinferr ZInferenceError�base_names_of_instance�any�instance_has_boolr )�selfr r0 Zlen_arg�instanceZaffected_by_pep8r r( r � visit_callo sB � ����z$ImplicitBooleanessChecker.visit_callznodes.ClassDefr )� class_defr c C s* z| � d� W dS tjy$ Y n0 dS )N�__bool__TF)�getattrr ZAttributeInferenceError)r>