관리-도구
편집 파일: implicit_booleaness_checker.cpython-311.pyc
� �܋f�$ � �| � d dl mZ d dlZd dlmZmZmZ d dlmZ d dlm Z d dl mZmZ G d� dej � � ZdS ) � )�annotationsN)�bases�nodes�util)�checkers)�utils)�HIGH� INFERENCEc � � e Zd ZdZdZdddddgifdd �Zd Z ej d� � d&d�� � Z e d'd�� � Z ej d� � d(d�� � Z ej d� � d)d�� � Z d)d�Zd*d�Zd+d!�Ze d,d$�� � Zd%S )-�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-lena Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.� old_names)�C1801zlen-as-condition)z7'%s' can be simplified to '%s' as an empty %s is falsey�&use-implicit-booleaness-not-comparisonz�Used when Pylint detects that collection literal comparison is being used to check for emptiness; Use implicit booleaness instead of a collection classes; empty collections are considered as false)�C1802�C1803� �node� nodes.Call�return�Nonec � �� t j |d� � sd S |j }t |t j � � r!|j }t |t j � � �!t j ||� � sd 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 xY w| � |� � �t'