U
    nuf9                     @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlm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eZG dd deZdS )    )ValueWrapper)ModuleValue)ParserTreeFilter)StubNameStubModuleName)TypingModuleFilterWrapper)ModuleContextc                       sR   e Zd ZeZ fddZdd Z fddZdd Zd fd
d	Z	dd Z
  ZS )StubModuleValuec                    s   t  j|| || _d S N)super__init__non_stub_value_set)selfr   argskwargs	__class__ E/tmp/pip-unpacked-wheel-ol4ehs9f/jedi/inference/gradual/stub_value.pyr      s    zStubModuleValue.__init__c                 C   s   dS )NTr   r   r   r   r   is_stub   s    zStubModuleValue.is_stubc              	      sP   i }| j D ]0}z
|j}W n tk
r,   Y q
X ||  q
|t   |S )z
        We have to overwrite this, because it's possible to have stubs that
        don't have code for all the child modules. At the time of writing this
        there are for example no stubs for `json.tool`.
        )r   sub_modules_dictAttributeErrorupdater   )r   namesvaluemethodr   r   r   r      s    

z StubModuleValue.sub_modules_dictc                 C   s   t |  |dgt|   S )N)Zparent_contextorigin_scope)
StubFilterZ
as_contextlistZiter_star_filters)r   r   r   r   r   _get_stub_filters$   s    
z!StubModuleValue._get_stub_filtersNc                 #   s:   t  |}t|d  | j|d}|E d H  |E d H  d S N)r   )r   get_filtersnextr    )r   r   filtersZstub_filtersr   r   r   r"   *   s
    

zStubModuleValue.get_filtersc                 C   s   t | S r
   )StubModuleContextr   r   r   r   _as_context1   s    zStubModuleValue._as_context)N)__name__
__module____qualname__r   Z_module_name_classr   r   r   r    r"   r&   __classcell__r   r   r   r   r	   	   s   r	   c                       s   e Zd Zd fdd	Z  ZS )r%   Nc                    s   t  j|dS r!   )r   r"   )r   Zuntil_positionr   r   r   r   r"   6   s    zStubModuleContext.get_filters)NNr'   r(   r)   r"   r*   r   r   r   r   r%   5   s   r%   c                       s$   e Zd Z fddZdd Z  ZS )TypingModuleWrapperc                 /   s<   t  j||}t|d }|d k	s$tt|V  |E d H  d S r
   )r   r"   r#   AssertionErrorr   )r   r   r   r$   fr   r   r   r"   =   s
    

zTypingModuleWrapper.get_filtersc                 C   s   t | S r
   )TypingModuleContextr   r   r   r   r&   D   s    zTypingModuleWrapper._as_context)r'   r(   r)   r"   r&   r*   r   r   r   r   r,   <   s   r,   c                       s   e Zd Z fddZ  ZS )r/   c                 /   s,   t  j||}tt|d V  |E d H  d S r
   )r   r"   r   r#   )r   r   r   r$   r   r   r   r"   I   s    zTypingModuleContext.get_filtersr+   r   r   r   r   r/   H   s   r/   c                       s    e Zd ZeZ fddZ  ZS )r   c                    sj   t  |sdS | }|d kr$dS |jdkr>|jjdkr>dS |j}|drf|drb|dsfdS dS )NF)Zimport_fromimport_name)Zimport_as_nameZdotted_as_name___T)r   _is_name_reachableZget_definitiontypeparentr   
startswithendswith)r   nameZ
definitionnr   r   r   r3   R   s    
zStubFilter._is_name_reachable)r'   r(   r)   r   Z
name_classr3   r*   r   r   r   r   r   O   s   r   c                   @   s   e Zd ZdS )VersionInfoN)r'   r(   r)   r   r   r   r   r:   e   s   r:   N)Zjedi.inference.base_valuer   Zjedi.inference.value.moduler   Zjedi.inference.filtersr   Zjedi.inference.namesr   r   Zjedi.inference.gradual.typingr   Zjedi.inference.contextr   r	   r%   r,   r/   r   r:   r   r   r   r   <module>   s   ,