o
    DDij                     @   s  U d dl Z d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZmZmZmZmZmZmZmZ d dlZdeeej  fddZee d	d
 dZeeej  ed< deeej  fddZee dd
 dZeeej  ed< i Zeeej eeej  f ed< eD ]Zeedd e eD ee< qdeej deej fddZ i Z!eeej eej f ed< eD ]Ze ee!e< qeddG dd dZ"dd eD Z#eeej e"f ed< de$de%fd d!Z&de$de$fd"d#Z'de$dee$ fd$d%Z(de$de%fd&d'Z)de$de%fd(d)Z*de$ddfd*d+Z+eD ]Zeep g D ]Z,e,j-d,kr+q!e+e,j. q!qee/Z0ee1ee1 f ed-< e!2 D ]\ZZ3ej45d.rSqFee3fD ]Z6e0e6j7 8e6j4 qWqFdS )/    N)defaultdict)Sequence)	dataclassfieldsreplace)DictIteratorListMappingr   SetTypeUnionreturnc                  c   s,    t tD ]} | dsqtt| V  qdS )z
    Get all base classes that are subclasses of CSTNode but not an actual
    node itself. This allows us to keep our types sane by refering to the
    base classes themselves.
    BaseN)dircst
startswithgetattr)name r   N/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codegen/gather.py
_get_bases   s   
r   c                 C      | j S N__name__)baser   r   r   <lambda>       r   )keytypeclassesc               	   c   sf    t tD ]+} | dr| drq| dkrqtt| }zt|tjr&|V  W q ty0   Y qw dS )zz
    Grab all CSTNodes that are not a superclass. Basically, anything that a
    person might use to generate a tree.
    __CSTNodeN)r   r   r   endswithr   
issubclassr"   	TypeError)r   noder   r   r   
_get_nodes"   s   
r'   c                 C   r   r   r   )r&   r   r   r   r   8   r   all_libcst_nodesnode_to_basesc                 C   s   g | ]
}t |tjr|qS r   )r$   r   r"   .0br   r   r   
<listcomp>>   s    r-   r&   c                 C   s   dd t |  D }|d S )Nc                 S   s   g | ]}|t v r|qS r   r)   r*   r   r   r   r-   E   s    z3_get_most_generic_base_for_node.<locals>.<listcomp>r   r.   )r&   exportable_basesr   r   r   _get_most_generic_base_for_nodeB   s   r0   	nodebasesT)frozenc                   @   s2   e Zd ZU dZeed< dZeed< dZeed< dS )UsageFmaybeoptionalsequenceN)r   
__module____qualname__r4   bool__annotations__r5   r6   r   r   r   r   r3   O   s   
 r3   c                 C   s   i | ]}|t  qS r   )r3   )r+   r&   r   r   r   
<dictcomp>V   s    r;   nodeusestypeobjc                 C   s$   zt | tjW S  ty   Y dS w )NF)r$   r   MaybeSentinelr%   r=   r   r   r   	_is_maybeY   s
   r@   c                 C   s   z| j W S  ty   Y d S w r   )
__origin__AttributeErrorr?   r   r   r   _get_origina   s
   rC   c                 C   s    z| j W S  ty   g  Y S w r   )__args__rB   r?   r   r   r   	_get_argsj   s
   rE   c                 C   s   t | }|tu p|tu S r   )rC   r   ABCSequence)r=   originr   r   r   _is_sequences   s   rH   c                 C   s   t | tu S r   )rC   r   r?   r   r   r   	_is_unionx   s   rI   c                 C   s   t | r?tdd t| D }tdd t| D }t| D ] }|tv r:tt| t| jp.|t| jp4|dt|< qt| qt	| r]t| D ]}|tv rXtt| ddt|< qGt| qGd S d S )Nc                 s   s    | ]}t |V  qd S r   )r@   r+   nr   r   r   	<genexpr>~   s    z#_calc_node_usage.<locals>.<genexpr>c                 s   s    | ]
}t |td V  qd S r   )
isinstancetyperJ   r   r   r   rL      s    )r4   r5   T)r6   )
rI   anyrE   r(   r   r<   r4   r5   _calc_node_usagerH   )r=   	has_maybehas_noner&   r   r   r   rP   |   s$   

rP   	_metadataimportsr   )9inspectcollectionsr   collections.abcr   rF   dataclassesr   r   r   typingr   r   r	   r
   r   r   r   libcstr   r"   r   sortedr    r:   r'   r(   r)   r&   listreversedgetmror0   r1   r3   r<   objectr9   r@   rC   rE   rH   rI   rP   fieldr   rN   setrT   stritemsr   r   r   xr7   addr   r   r   r   <module>   s\   
(

$
 $		