a
    ÷£Be+G  ã                   @   s2  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ eƒ ZG dd„ deƒZG dd„ dƒZG dd„ deƒZd&dd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZ d d!„ Z!G d"d#„ d#ƒZ"e"g ƒZ#d$d%„ Z$dS )'a4  
Values are the "values" that Python would return. However Values are at the
same time also the "values" that a user is currently sitting in.

A ValueSet is typically used to specify the return of a function or any other
static analysis operation. In jedi there are always multiple returns and not
just one.
é    )Úreduce)Úadd)Úzip_longest)ÚName)Údebug)Úclean_scope_docstring©ÚSimpleGetItemNotFound)Úsafe_property)Ú%inference_state_as_method_param_cache)Úmemoize_methodc                   @   s   e Zd ZdS )ÚHasNoContextN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jedi/inference/base_value.pyr      s   r   c                   @   s�   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zd"dd„Zdd„ Z	d#dd„Z
d$dd„Zdd„ Zdd„ Zd%dd„Zdd„ Zdd„ Zed d!„ ƒZdS )&ÚHelperValueMixinc                 C   s0   | }|j d u r| ¡ S |j d u r$|S |j }qd S ©N)Úparent_contextÚ
as_context)ÚselfÚvaluer   r   r   Úget_root_context   s    

z!HelperValueMixin.get_root_contextc                 C   s   | j j| |d�S )N©Ú	arguments©Úinference_stateÚexecute©r   r   r   r   r   r   (   s    zHelperValueMixin.executec                 G   s,   ddl m} |dd„ |D ƒƒ}| j | |¡S )Nr   )ÚValuesArgumentsc                 S   s   g | ]}t |gƒ‘qS r   ©ÚValueSet©Ú.0r   r   r   r   Ú
<listcomp>-   ó    z8HelperValueMixin.execute_with_values.<locals>.<listcomp>)Zjedi.inference.argumentsr    r   r   )r   Z
value_listr    r   r   r   r   Úexecute_with_values+   s    z$HelperValueMixin.execute_with_valuesc                 C   s   |   ¡ S r   ©r'   ©r   r   r   r   Úexecute_annotation0   s    z#HelperValueMixin.execute_annotationc                 C   s
   t | gƒS r   r!   r)   r   r   r   Úgather_annotation_classes3   s    z*HelperValueMixin.gather_annotation_classesNFc                 C   s   t  dd„ |  ||¡D ƒ¡S )Nc                 s   s   | ]}|  ¡ V  qd S r   ©Úinfer©r$   Z
lazy_valuer   r   r   Ú	<genexpr>7   s   ÿz:HelperValueMixin.merge_types_of_iterate.<locals>.<genexpr>©r"   Ú	from_setsÚiterate)r   Úcontextualized_nodeÚis_asyncr   r   r   Úmerge_types_of_iterate6   s    

þz'HelperValueMixin.merge_types_of_iteratec                 c   s^   t |tƒr|nd }| j|d�E d H  |  ¡ rZddlm} |t| hƒƒD ]}| ¡ E d H  qFd S )N)Úorigin_scoper   )Úconvert_values)Ú
isinstancer   Zget_filtersÚis_stubZ!jedi.inference.gradual.conversionr7   r"   )r   Úname_or_strr6   r7   Úcr   r   r   Ú_get_value_filters<   s    z#HelperValueMixin._get_value_filtersTc                 C   s6   ddl m} |  |¡}| ||¡}t d|| |¡ |S )Nr   )Úfinderzcontext.goto %s in (%s): %s)Újedi.inferencer=   r<   Zfilter_namer   Údbg)r   r:   Úname_contextÚanalysis_errorsr=   ÚfiltersÚnamesr   r   r   ÚgotoE   s
    
zHelperValueMixin.gotoc           	      C   s’   |du r| }|   |||¡}t dd„ |D ƒ¡}|sPt|tƒrB|jn|}|  |¡}|s€|s€|r€t|tƒr€ddlm} | 	|| |¡ t
 d||¡ |S )zZ
        :param position: Position of the last statement -> tuple of line, column
        Nc                 s   s   | ]}|  ¡ V  qd S r   r,   )r$   Únamer   r   r   r/   T   r&   z6HelperValueMixin.py__getattribute__.<locals>.<genexpr>r   ©Úanalysisz context.names_to_types: %s -> %s)rD   r"   r1   r8   r   r   Úpy__getattribute__alternativesr>   rG   Zadd_attribute_errorr   r?   )	r   r:   r@   ÚpositionrA   rC   ÚvaluesÚnrG   r   r   r   Úpy__getattribute__L   s    

ÿz#HelperValueMixin.py__getattribute__c                 C   s"   |   d¡}|st d| ¡ | ¡ S )NÚ	__await__z"Tried to run __await__ on value %s)rL   r   Úwarningr'   )r   Zawait_value_setr   r   r   Úpy__await__a   s    
zHelperValueMixin.py__await__c                 C   s   | j jS r   )rE   Ústring_namer)   r   r   r   Ú
py__name__g   s    zHelperValueMixin.py__name__c                 C   sV   t  d| ¡ |rLddlm} t||  d¡ ¡  d¡ ¡  d¡ ¡  ¡ ƒgƒS |  |¡S )Nz
iterate %sr   )ÚLazyKnownValuesÚ	__aiter__Ú	__anext__rM   )	r   r?   Újedi.inference.lazy_valuerR   ÚiterrL   r'   Úpy__stop_iteration_returnsÚ
py__iter__)r   r3   r4   rR   r   r   r   r2   j   s    ÿþ
ÿÿzHelperValueMixin.iteratec                 C   s‚   t jd| |f dd��X |  ¡ D ].}| |¡r t jddd�  W d   ƒ dS q t jddd� W d   ƒ dS 1 st0    Y  d S )Nzsubclass matching of %s <=> %sZBLUE)Úcolorzmatched subclass TrueTzmatched subclass FalseF)r   Úincrease_indent_cmZ	py__mro__Úis_same_classr?   )r   Úclass_valueÚclsr   r   r   Úis_sub_class_ofz   s    ÿ
z HelperValueMixin.is_sub_class_ofc                 C   s"   t |ƒjtjkr| | ¡S | |kS r   )Útyper[   r   )r   Zclass2r   r   r   r[   „   s    
zHelperValueMixin.is_same_classc                 O   s   | j |i |¤ŽS r   )Ú_as_context©r   ÚargsÚkwargsr   r   r   r   Š   s    zHelperValueMixin.as_context)NF)NT)NNT)NF)r   r   r   r   r   r'   r*   r+   r5   r<   rD   rL   rO   rQ   r2   r^   r[   r   r   r   r   r   r   r      s$   

	
  ÿ


r   c                   @   s  e Zd ZdZdZdZdZdAdd„Zdd„ Zdd	„ Z	dBd
d„Z
dCdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zefd&d'„Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Z d6d7„ Z!d8d9„ Z"e#d:d;„ ƒZ$dDd=d>„Z%d?d@„ Z&dS )EÚValuez*
    To be implemented by subclasses.
    NZnot_defined_please_report_bugc                 C   s   || _ || _d S r   )r   r   )r   r   r   r   r   r   Ú__init__™   s    zValue.__init__c                 C   s*   ddl m} |j|jd|jd|  d� tS )Nr   rF   ztype-error-not-subscriptablez+TypeError: '%s' object is not subscriptable©Úmessage)r>   rG   r   ÚcontextÚnodeÚ	NO_VALUES)r   Zindex_value_setr3   rG   r   r   r   Úpy__getitem__�   s    üzValue.py__getitem__c                 C   s   t ‚d S r   r   )r   Úindexr   r   r   Úpy__simple_getitem__¨   s    zValue.py__simple_getitem__c                 C   s6   |d ur.ddl m} |j|jd|jd|  d� tg ƒS )Nr   rF   ztype-error-not-iterablez&TypeError: '%s' object is not iterablerf   )r>   rG   r   rh   ri   rV   )r   r3   rG   r   r   r   rX   «   s    üzValue.py__iter__c                 C   s
   |   |¡S r   )rX   )r   r3   r   r   r   Ú
py__next__µ   s    zValue.py__next__c                 C   s   g S r   r   r)   r   r   r   Úget_signatures¸   s    zValue.get_signaturesc                 C   s   dS ©NFr   r)   r   r   r   Úis_class»   s    zValue.is_classc                 C   s   dS rp   r   r)   r   r   r   Úis_class_mixin¾   s    zValue.is_class_mixinc                 C   s   dS rp   r   r)   r   r   r   Úis_instanceÁ   s    zValue.is_instancec                 C   s   dS rp   r   r)   r   r   r   Úis_functionÄ   s    zValue.is_functionc                 C   s   dS rp   r   r)   r   r   r   Ú	is_moduleÇ   s    zValue.is_modulec                 C   s   dS rp   r   r)   r   r   r   Úis_namespaceÊ   s    zValue.is_namespacec                 C   s   dS rp   r   r)   r   r   r   Úis_compiledÍ   s    zValue.is_compiledc                 C   s   dS rp   r   r)   r   r   r   Úis_bound_methodÐ   s    zValue.is_bound_methodc                 C   s   dS rp   r   r)   r   r   r   Úis_builtins_moduleÓ   s    zValue.is_builtins_modulec                 C   s   dS )z‚
        Since Wrapper is a super class for classes, functions and modules,
        the return value will always be true.
        Tr   r)   r   r   r   Ú
py__bool__Ö   s    zValue.py__bool__c                 C   s0   z| j j W n ty    Y dS 0 t| j ƒS d S )NÚ )Ú	tree_nodeZget_doc_nodeÚAttributeErrorr   r)   r   r   r   Ú	py__doc__Ý   s
    zValue.py__doc__c                 C   s   |t u rtd|  ƒ‚|S )Nz'There exists no safe value for value %s)ÚsentinelÚ
ValueError)r   Údefaultr   r   r   Úget_safe_valueå   s    zValue.get_safe_valuec                 C   s   t  d|| |¡ tS )Nz!%s not possible between %s and %s©r   rN   rj   )r   ÚotherÚoperatorr   r   r   Úexecute_operationê   s    zValue.execute_operationc                 C   s   t  d| ¡ tS )Nzno execution possible %srƒ   r   r   r   r   Ú
py__call__î   s    zValue.py__call__c                 C   s   t  d| ¡ tS )Nz0Not possible to return the stop iterations of %srƒ   r)   r   r   r   rW   ò   s    z Value.py__stop_iteration_returnsc                 C   s   t S )zH
        For now a way to add values in cases like __getattr__.
        )rj   )r   r:   r   r   r   rH   ö   s    z$Value.py__getattribute__alternativesc                 C   s   t  d| ¡ t| gƒS )NzNo __get__ defined on %s)r   rN   r"   )r   Úinstancer\   r   r   r   Ú	py__get__ü   s    zValue.py__get__c                 C   s   t S r   )ÚNotImplemented)r   Zcalling_instancerˆ   r\   r   r   r   Úpy__get__on_class   s    zValue.py__get__on_classc                 C   s   d S r   r   r)   r   r   r   Úget_qualified_names  s    zValue.get_qualified_namesc                 C   s
   | j  ¡ S r   )r   r9   r)   r   r   r   r9     s    zValue.is_stubc                 C   s   t ‚d S r   )r   r)   r   r   r   r`     s    zValue._as_contextc                 C   s   t ‚d S r   ©ÚNotImplementedErrorr)   r   r   r   rE     s    z
Value.nameTc                 C   s   d S r   r   )r   Úadd_class_infor   r   r   Úget_type_hint  s    zValue.get_type_hintc                 C   s   i S )an  
        When the current instance represents a type annotation, this method
        tries to find information about undefined type vars and returns a dict
        from type var name to value set.

        This is for example important to understand what `iter([1])` returns.
        According to typeshed, `iter` returns an `Iterator[_T]`:

            def iter(iterable: Iterable[_T]) -> Iterator[_T]: ...

        This functions would generate `int` for `_T` in this case, because it
        unpacks the `Iterable`.

        Parameters
        ----------

        `self`: represents the annotation of the current parameter to infer the
            value for. In the above example, this would initially be the
            `Iterable[_T]` of the `iterable` parameter and then, when recursing,
            just the `_T` generic parameter.

        `value_set`: represents the actual argument passed to the parameter
            we're inferred for, or (for recursive calls) their types. In the
            above example this would first be the representation of the list
            `[1]` and then, when recursing, just of `1`.
        r   )r   Ú	value_setr   r   r   Úinfer_type_vars  s    zValue.infer_type_vars)N)N)N)T)'r   r   r   Ú__doc__r|   Z
array_typeZapi_typere   rk   rm   rX   rn   ro   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r~   r   r‚   r†   r‡   rW   rH   r‰   r‹   rŒ   r9   r`   ÚpropertyrE   r�   r’   r   r   r   r   rd   �   sF   





rd   NFc                 C   s   t  dd„ | j||d�D ƒ¡S )zƒ
    Calls `iterate`, on all values but ignores the ordering and just returns
    all values that the iterate functions yield.
    c                 s   s   | ]}|  ¡ V  qd S r   r,   r.   r   r   r   r/   8  s   ÿz!iterate_values.<locals>.<genexpr>©r4   r0   )rJ   r3   r4   r   r   r   Úiterate_values3  s    
þr–   c                   @   s2   e Zd Zedd„ ƒZeeƒ dd„ ƒƒZdd„ ZdS )Ú_ValueWrapperBasec                 C   sF   ddl m} | jj}|jd ur*|| |jƒS ddlm} || |jƒS d S )Nr   )Ú	ValueName)ÚCompiledValueName)Zjedi.inference.namesr˜   Ú_wrapped_valuerE   Z	tree_nameZjedi.inference.compiledr™   rP   )r   r˜   Zwrapped_namer™   r   r   r   rE   ?  s    
z_ValueWrapperBase.namec                 O   s   | |i |¤ŽS r   r   )r]   r   rb   rc   r   r   r   Úcreate_cachedI  s    z_ValueWrapperBase.create_cachedc                 C   s   |dksJ dƒ‚t | j|ƒS )Nrš   zProblem with _get_wrapped_value)Úgetattrrš   )r   rE   r   r   r   Ú__getattr__N  s    z_ValueWrapperBase.__getattr__N)	r   r   r   r
   rE   Úclassmethodr   r›   r�   r   r   r   r   r—   >  s   
	r—   c                   @   s,   e Zd Zeedd„ ƒƒZdd„ Zdd„ ZdS )ÚLazyValueWrapperc                 C   s6   t  d¡� |  ¡ W  d   ƒ S 1 s(0    Y  d S )NzResolve lazy value wrapper)r   rZ   Ú_get_wrapped_valuer)   r   r   r   rš   T  s    zLazyValueWrapper._wrapped_valuec                 C   s   d| j j S )Nz<%s>)Ú	__class__r   r)   r   r   r   Ú__repr__Z  s    zLazyValueWrapper.__repr__c                 C   s   t ‚d S r   r�   r)   r   r   r   r    ]  s    z#LazyValueWrapper._get_wrapped_valueN)r   r   r   r
   r   rš   r¢   r    r   r   r   r   rŸ   S  s
   rŸ   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚValueWrapperc                 C   s
   || _ d S r   )rš   )r   Zwrapped_valuer   r   r   re   b  s    zValueWrapper.__init__c                 C   s   d| j j| jf S )Nz%s(%s))r¡   r   rš   r)   r   r   r   r¢   e  s    zValueWrapper.__repr__N)r   r   r   re   r¢   r   r   r   r   r£   a  s   r£   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )Ú	TreeValuec                    s   t ƒ  ||¡ || _d S r   )Úsuperre   r|   )r   r   r   r|   ©r¡   r   r   re   j  s    zTreeValue.__init__c                 C   s   d| j j| jf S )Nz<%s: %s>)r¡   r   r|   r)   r   r   r   r¢   n  s    zTreeValue.__repr__)r   r   r   re   r¢   Ú__classcell__r   r   r¦   r   r¤   i  s   r¤   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚContextualizedNodec                 C   s   || _ || _d S r   )rh   ri   )r   rh   ri   r   r   r   re   s  s    zContextualizedNode.__init__c                 C   s
   | j  ¡ S r   )rh   r   r)   r   r   r   r   w  s    z#ContextualizedNode.get_root_contextc                 C   s   | j  | j¡S r   )rh   Z
infer_noderi   r)   r   r   r   r-   z  s    zContextualizedNode.inferc                 C   s   d| j j| j| jf S )Nz<%s: %s in %s>)r¡   r   ri   rh   r)   r   r   r   r¢   }  s    zContextualizedNode.__repr__N)r   r   r   re   r   r-   r¢   r   r   r   r   r¨   r  s   r¨   c              	   C   s–   t }tƒ }|D ]Z}|jd d�}t|ƒtttttfv r^z||  	|¡O }W qW n t
y\   Y n0 | |¡ q|sr|s†||  t|ƒ|¡O }t d|¡ |S )N)r�   zpy__getitem__ result: %s)rj   Úsetr‚   r_   ÚfloatÚintÚstrÚsliceÚbytesrm   r	   r   rk   r"   r   r?   )r   Zindex_valuesr3   ÚresultZunused_valuesZindex_valuerl   r   r   r   Ú_getitem�  s$    þr°   c                   @   sè   e Zd Zdd„ Zedd„ ƒZedd„ ƒZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd8d!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd9d4d5„Zd6d7„ ZdS ):r"   c                 C   s&   t |ƒ| _|D ]}t|tƒrJ ‚qd S r   )Ú	frozensetÚ_setr8   r"   )r   Úiterabler   r   r   r   re   �  s    
zValueSet.__init__c                 C   s   |   | ¡}||_|S r   )Ú__new__r²   )r]   Z
frozenset_r   r   r   r   Ú_from_frozen_set¢  s    
zValueSet._from_frozen_setc                 C   s@   t ƒ }|D ]&}t|tƒr$||jO }q
|t|ƒO }q
|  t|ƒ¡S )z7
        Used to work with an iterable of set.
        )r©   r8   r"   r²   r±   rµ   )r]   ZsetsZ
aggregatedÚset_r   r   r   r1   ¨  s    
zValueSet.from_setsc                 C   s   |   | j|jB ¡S r   ©rµ   r²   ©r   r„   r   r   r   Ú__or__µ  s    zValueSet.__or__c                 C   s   |   | j|j@ ¡S r   r·   r¸   r   r   r   Ú__and__¸  s    zValueSet.__and__c                 C   s
   t | jƒS r   )rV   r²   r)   r   r   r   Ú__iter__»  s    zValueSet.__iter__c                 C   s
   t | jƒS r   )Úboolr²   r)   r   r   r   Ú__bool__¾  s    zValueSet.__bool__c                 C   s
   t | jƒS r   )Úlenr²   r)   r   r   r   Ú__len__Á  s    zValueSet.__len__c                 C   s   dd  dd„ | jD ƒ¡ S )NzS{%s}ú, c                 s   s   | ]}t |ƒV  qd S r   )r¬   )r$   Úsr   r   r   r/   Å  r&   z$ValueSet.__repr__.<locals>.<genexpr>)Újoinr²   r)   r   r   r   r¢   Ä  s    zValueSet.__repr__c                 C   s   |   t|| jƒ¡S r   )r¡   Úfilterr²   )r   Zfilter_funcr   r   r   rÃ   Ç  s    zValueSet.filterc                    s   ‡ ‡fdd„}|S )Nc                     s   ˆ  ‡ ‡‡fdd„ˆjD ƒ¡S )Nc                 3   s"   | ]}t |ˆƒˆ i ˆ¤ŽV  qd S r   )rœ   r#   )rb   rc   rE   r   r   r/   Ì  s   ÿz7ValueSet.__getattr__.<locals>.mapper.<locals>.<genexpr>)r1   r²   ©rb   rc   ©rE   r   rÄ   r   ÚmapperË  s    þz$ValueSet.__getattr__.<locals>.mapperr   )r   rE   rÆ   r   rÅ   r   r�   Ê  s    zValueSet.__getattr__c                 C   s   | j |j kS r   ©r²   r¸   r   r   r   Ú__eq__Ò  s    zValueSet.__eq__c                 C   s   |   |¡ S r   )rÈ   r¸   r   r   r   Ú__ne__Õ  s    zValueSet.__ne__c                 C   s
   t | jƒS r   )Úhashr²   r)   r   r   r   Ú__hash__Ø  s    zValueSet.__hash__c                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|  ¡ V  qd S r   )Úpy__class__©r$   r;   r   r   r   r/   Ü  r&   z'ValueSet.py__class__.<locals>.<genexpr>)r"   r²   r)   r   r   r   rÌ   Û  s    zValueSet.py__class__NFc                 #   sH   ddl m} ‡ ‡fdd„| jD ƒ}t|Ž D ]}|dd„ |D ƒƒV  q*d S )Nr   )Úget_merged_lazy_valuec                    s   g | ]}|j ˆ ˆd �‘qS )r•   )r2   rÍ   ©r3   r4   r   r   r%   à  r&   z$ValueSet.iterate.<locals>.<listcomp>c                 S   s   g | ]}|d ur|‘qS r   r   )r$   Úlr   r   r   r%   ã  r&   )rU   rÎ   r²   r   )r   r3   r4   rÎ   Z
type_itersZlazy_valuesr   rÏ   r   r2   Þ  s    ÿzValueSet.iteratec                    s   t  ‡ fdd„| jD ƒ¡S )Nc                 3   s   | ]}|j  |ˆ ¡V  qd S r   r   rÍ   r   r   r   r/   ç  r&   z#ValueSet.execute.<locals>.<genexpr>©r"   r1   r²   r   r   r   r   r   æ  s    zValueSet.executec                    s   t  ‡ ‡fdd„| jD ƒ¡S )Nc                 3   s   | ]}|j ˆ i ˆ¤ŽV  qd S r   r(   rÍ   rÄ   r   r   r/   ê  r&   z/ValueSet.execute_with_values.<locals>.<genexpr>rÑ   ra   r   rÄ   r   r'   é  s    zValueSet.execute_with_valuesc                    s   t t‡ ‡fdd„| jD ƒg ƒS )Nc                    s   g | ]}|j ˆ i ˆ¤Ž‘qS r   )rD   rÍ   rÄ   r   r   r%   í  r&   z!ValueSet.goto.<locals>.<listcomp>)r   r   r²   ra   r   rÄ   r   rD   ì  s    zValueSet.gotoc                    s   t  ‡ ‡fdd„| jD ƒ¡S )Nc                 3   s   | ]}|j ˆ i ˆ¤ŽV  qd S r   )rL   rÍ   rÄ   r   r   r/   ð  r&   z.ValueSet.py__getattribute__.<locals>.<genexpr>rÑ   ra   r   rÄ   r   rL   ï  s    zValueSet.py__getattribute__c                    s   t  ‡ ‡fdd„| jD ƒ¡S )Nc                 3   s$   | ]}t |gˆ ¢R i ˆ¤ŽV  qd S r   )r°   rÍ   rÄ   r   r   r/   ó  r&   z$ValueSet.get_item.<locals>.<genexpr>rÑ   ra   r   rÄ   r   Úget_itemò  s    zValueSet.get_itemc              	   C   sF   |   g ¡}| jD ]0}zt||ƒ}W n ty4   Y q0 ||ƒ O }q|S r   )r¡   r²   rœ   r}   )r   Zfunction_namer‘   r;   Úmethodr   r   r   Ú	try_mergeõ  s    

zValueSet.try_mergec                 C   s   t  dd„ | jD ƒ¡S )Nc                 S   s   g | ]}|  ¡ ‘qS r   )r+   rÍ   r   r   r   r%     r&   z6ValueSet.gather_annotation_classes.<locals>.<listcomp>rÑ   r)   r   r   r   r+      s    z"ValueSet.gather_annotation_classesc                 C   s   dd„ | j D ƒS )Nc                 S   s   g | ]}|  ¡ D ]}|‘qqS r   )ro   )r$   r;   Úsigr   r   r   r%     r&   z+ValueSet.get_signatures.<locals>.<listcomp>rÇ   r)   r   r   r   ro     s    zValueSet.get_signaturesTc                    s�   ‡ fdd„| j D ƒ}ttd |ƒƒ}t|ƒdkr6|d S d|v }|rL| d¡ t|ƒdkr\d S t|ƒdkrr|d }ndd |¡ }|rŒd| }|S )	Nc                    s   g | ]}|j ˆ d �‘qS )©r�   )r�   )r$   ÚvrÖ   r   r   r%     r&   z*ValueSet.get_type_hint.<locals>.<listcomp>é   r   ÚNonez	Union[%s]rÀ   zOptional[%s])r²   ÚsortedrÃ   r¾   ÚremoverÂ   )r   r�   ÚtZ
type_hintsÚoptionalrÁ   r   rÖ   r   r�     s    

zValueSet.get_type_hintc                 C   s0   ddl m} i }| jD ]}||| |¡ƒ q|S )Nr   )Úmerge_type_var_dicts)Z!jedi.inference.gradual.annotationrÞ   r²   r’   )r   r‘   rÞ   Ztype_var_dictr   r   r   r   r’     s    
þzValueSet.infer_type_vars)NF)T)r   r   r   re   rž   rµ   r1   r¹   rº   r»   r½   r¿   r¢   rÃ   r�   rÈ   rÉ   rË   rÌ   r2   r   r'   rD   rL   rÒ   rÔ   r+   ro   r�   r’   r   r   r   r   r"   œ  s8   



r"   c                    s   ‡ fdd„}|S )Nc                     s   t ˆ | i |¤ŽƒS r   r!   rÄ   ©Úfuncr   r   Úwrapper+  s    z&iterator_to_value_set.<locals>.wrapperr   )rà   rá   r   rß   r   Úiterator_to_value_set*  s    râ   )NF)%r“   Ú	functoolsr   r…   r   Ú	itertoolsr   Zparso.python.treer   Zjedir   Zjedi.parser_utilsr   Zjedi.inference.helpersr	   Zjedi.inference.utilsr
   Zjedi.inference.cacher   Z
jedi.cacher   Úobjectr   Ú	Exceptionr   r   rd   r–   r—   rŸ   r£   r¤   r¨   r°   r"   rj   râ   r   r   r   r   Ú<module>   s4   r %
	 