관리-도구
편집 파일: for_any_all.cpython-311.pyc
� �܋f� � � � d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m Z mZmZ ddl mZ erddlmZ G d � d e� � Zdd�ZdS )z;Check for use of for loops that only check for a condition.� )�annotations)� TYPE_CHECKING)�nodes)�BaseChecker)� assigned_bool�only_required_for_messages�returns_bool)�HIGH)�PyLinterc � � e Zd ZdZddiZ ed� � dd�� � Zedd�� � Zedd�� � Z edd�� � Z dS )�ConsiderUsingAnyOrAllChecker�consider-using-any-or-all�C0501)z`for` loop could be `%s`r zYA for loop that checks for a condition and return a bool can be replaced with any or all.�node� nodes.For�return�Nonec � � t |j � � dk rd S t |j d t j � � sd S t |j d � � � � � }t d� |D � � � � rd S |� � � }| � |||� � rB|j j }| � ||� � }| � d||t �� � d S | � ||� � rB|j j }| � ||� � }| � d||t �� � d S d S )N� r c 3 �J K � | ]}t |t j � � V � �d S �N)� isinstancer �If)�.0�childs �n/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/pylint/extensions/for_any_all.py� <genexpr>z9ConsiderUsingAnyOrAllChecker.visit_for.<locals>.<genexpr>+ s. � � � �D�D�u�z�%���*�*�D�D�D�D�D�D� r )r �args� confidence)�len�bodyr r r �list�get_children�any�next_sibling�_assigned_reassigned_returned�value�name�_build_suggested_string�add_messager �_if_statement_returns_bool)�selfr �if_children�node_after_loop�final_return_bool�suggested_strings r � visit_forz&ConsiderUsingAnyOrAllChecker.visit_for# sq � ��t�y�>�>�Q����F��$�)�A�,���1�1� ��F��4�9�Q�<�4�4�6�6�7�7���D�D��D�D�D�D�D� � �F��+�+�-�-���-�-�d�K��Q�Q� � /� 5� :��#�;�;�D�BS�T�T�����+��%�� � � � � �F��*�*�;��H�H� � /� 5� ;��#�;�;�D�BS�T�T�����+��%�� � � � � �F� � r r. �list[nodes.NodeNG]r/ �nodes.NodeNG�boolc �x � t | � � dk sdS t | d � � sdS t |� � S )z�Detect for-loop, if-statement, return pattern: Ex: def any_uneven(items): for item in items: if not item % 2 == 0: return True return False � Fr )r! r )r. r/ s r r, z7ConsiderUsingAnyOrAllChecker._if_statement_returns_boolH sE � � �;���1�$�$��5��K��N�+�+� ��5� �O�,�,�,r c �� � | � � � }t |� � sdS d� |D � � }|sdS |d j d }|j d }t |t j � � rt |t j � � sdS |j d j }|j |k oHt |t j � � o.t |j t j � � o|j j |k S )al Detect boolean-assign, for-loop, re-assign, return pattern: Ex: def check_lines(lines, max_chars): long_line = False for line in lines: if len(line) > max_chars: long_line = True # no elif / else statement return long_line Fc �F � g | ]}t |t j � � �|��S � )r r �Assign)r �xs r � <listcomp>zNConsiderUsingAnyOrAllChecker._assigned_reassigned_returned.<locals>.<listcomp>s s) � �Q�Q�Q��Z��5�<�5P�5P�Q�1�Q�Q�Qr r ) �previous_siblingr �targetsr r � AssignNamer) �Returnr( �Name)r r. r/ �node_before_loop�assign_children�first_target�target_before_loop�node_before_loop_names r r'