AlkantarClanX12

Your IP : 3.12.154.133


Current Path : /opt/alt/python311/lib64/python3.11/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/lib2to3/fixes/__pycache__/fix_idioms.cpython-311.pyc

�

c��f��d�dZddlmZddlmZmZmZmZmZm	Z	dZ
dZGd�dej��Z
dS)	a�Adjust some old Python 2 idioms to their modern counterparts.

* Change some type comparisons to isinstance() calls:
    type(x) == T -> isinstance(x, T)
    type(x) is T -> isinstance(x, T)
    type(x) != T -> not isinstance(x, T)
    type(x) is not T -> not isinstance(x, T)

* Change "while 1:" into "while True:".

* Change both

    v = list(EXPR)
    v.sort()
    foo(v)

and the more general

    v = EXPR
    v.sort()
    foo(v)

into

    v = sorted(EXPR)
    foo(v)
�)�
fixer_base)�Call�Comma�Name�Node�	BlankLine�symsz0(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)z(power< 'type' trailer< '(' x=any ')' > >c	�X��eZdZdZde�de�de�de�d�	Z�fd�Zd�Zd�Z	d	�Z
d
�Z�xZS)�	FixIdiomsTz 
        isinstance=comparison< � z8 T=any >
        |
        isinstance=comparison< T=any aX >
        |
        while_stmt< 'while' while='1' ':' any+ >
        |
        sorted=any<
            any*
            simple_stmt<
              expr_stmt< id1=any '='
                         power< list='list' trailer< '(' (not arglist<any+>) any ')' > >
              >
              '\n'
            >
            sort=
            simple_stmt<
              power< id2=any
                     trailer< '.' 'sort' > trailer< '(' ')' >
              >
              '\n'
            >
            next=any*
        >
        |
        sorted=any<
            any*
            simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' >
            sort=
            simple_stmt<
              power< id2=any
                     trailer< '.' 'sort' > trailer< '(' ')' >
              >
              '\n'
            >
            next=any*
        >
    c���tt|���|��}|rd|vr|d|dkr|SdS|S)N�sorted�id1�id2)�superr�match)�self�node�r�	__class__s   ��?/opt/alt/python311/lib64/python3.11/lib2to3/fixes/fix_idioms.pyrzFixIdioms.matchOsT����)�T�"�"�(�(��.�.��
�	��Q�����x�1�U�8�#�#����4���c��d|vr|�||��Sd|vr|�||��Sd|vr|�||��Std���)N�
isinstance�whilerz
Invalid match)�transform_isinstance�transform_while�transform_sort�RuntimeError)rr�resultss   r�	transformzFixIdioms.transformZss���7�"�"��,�,�T�7�;�;�;�
��
�
��'�'��g�6�6�6�
��
 �
 ��&�&�t�W�5�5�5���/�/�/rc�b�|d���}|d���}d|_d|_ttd��|t	��|g��}d|vr0d|_ttjtd��|g��}|j|_|S)N�x�T�rr�n�not)�clone�prefixrrrrr	�not_test)rrr r#r$�tests      rrzFixIdioms.transform_isinstanceds����C�L��� � ���C�L��� � ���������D��&�&��E�G�G�Q��8�8���'�>�>��D�K���
��U���T�':�;�;�D��k����rc�h�|d}|�td|j�����dS)Nr�True�r))�replacerr))rrr �ones    rrzFixIdioms.transform_whileps3���g������D���
�3�3�3�4�4�4�4�4rc�@�|d}|d}|�d��}|�d��}|r*|�td|j�����ne|rT|���}d|_|�ttd��|g|j�����nt
d���|���|j}d	|vr�|rJ|�d	��d
|d
jf}	d	�	|	��|d
_dS|j
sJ�|j�J�t��}
|j
�
|
��|j|
usJ�|�d	��d
|
_dSdS)N�sort�next�list�exprrr.r%zshould not have reached here�
�)�getr/rr)r(rr�remove�
rpartition�join�parent�next_siblingr�append_child)rrr �	sort_stmt�	next_stmt�	list_call�simple_expr�new�btwn�prefix_lines�end_lines           rrzFixIdioms.transform_sortts����F�O�	��F�O�	��K�K��'�'�	��k�k�&�)�)���	?����d�8�I�4D�E�E�E�F�F�F�F�
�	?��#�#�%�%�C��C�J�����T�(�^�^�c�U�,7�,>�!@�!@�!@�
A�
A�
A�
A��=�>�>�>�����������4�<�<��
;�!%���� 5� 5�a� 8�)�A�,�:M�N��&*�i�i��&=�&=�	�!��#�#�#� �'�'�'�'� �-�5�5�5�$�;�;��� �-�-�h�7�7�7� �-��9�9�9�9�#'�/�/�$�"7�"7��":�����!�<r)
�__name__�
__module__�__qualname__�explicit�TYPE�CMP�PATTERNrr!rrr�
__classcell__)rs@rrr%s���������H�H�N�4�4����c�c�c�4�4�4�K%!�G�N	�	�	�	�	�0�0�0�
�
�
�5�5�5�$;�$;�$;�$;�$;�$;�$;rrN)�__doc__r%r�
fixer_utilrrrrrr	rLrK�BaseFixr�rr�<module>rSs�����<������A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�8��1��s;�s;�s;�s;�s;�
�"�s;�s;�s;�s;�s;r