a
    ,=ic¢  ã                   @   sl   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddlm	Z	 G dd	„ d	e
ƒZd
d„ ZdS )z$Inline constants in a python module.é    )Úabsolute_import)Údivision)Úprint_functionN)Ú	ast_utils)Úscopec                   @   s   e Zd ZdS )ÚInlineErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   úe/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/pasta/augment/inline.pyr      s   r   c                    s  t  | ¡}|jˆ  }t|jtjƒs8tdˆ t|jƒf ƒ‚| 	|j¡}t|tj
ƒs\tdˆ  ƒ‚|j}t| 	|¡tjƒs€tdˆ  ƒ‚|jD ]$}tt|ddƒtjƒr†tdˆ  ƒ‚q†|jD ]}t | 	|¡|t |¡¡ q²t|jƒdkrôt | 	|¡|¡ n‡ fdd	„|jD ƒ}||_dS )
z%Inline a constant name into a module.z$%r is not a constant; it has type %rz#%r is not declared in an assignmentz%r is not a top-level nameÚctxNz%r is not a constanté   c                    s&   g | ]}t |tjƒr|jˆ ks|‘qS r   )Ú
isinstanceÚastÚNameÚid)Ú.0Ztgt©Únamer   r   Ú
<listcomp>?   s   ÿzinline_name.<locals>.<listcomp>)r   ZanalyzeÚnamesr   Ú
definitionr   r   r   ÚtypeÚparentÚAssignÚvalueÚModuleZreadsÚgetattrÚStorer   Zreplace_childÚcopyÚdeepcopyÚlenÚtargetsZremove_child)Útr   ÚscÚ	name_nodeZassign_noder   ÚrefZtgt_listr   r   r   Úinline_name    s*    


ÿ

r(   )Ú__doc__Ú
__future__r   r   r   r   r    Z
pasta.baser   r   Ú	Exceptionr   r(   r   r   r   r   Ú<module>   s   