B
    /dS                 @   s   d Z ddlmZ ddlmZ ddlmZ dedfdedfd	e	d
fde
dfde
dfde
dfde
dfde
dfde
dfde
dfde
dfde
dfde
dfdedfdedfdZG dd dZG dd deZdedfddZdd  Zd!d" Zd%d#d$ZdS )&z
Module for statical analysis.
    )tree)debug)	is_string   zPotential AttributeError.   zPotential NameError.   zPotential ImportError.   N            	   
                  )zattribute-errorz
name-errorzimport-errorztype-error-too-many-argumentsztype-error-too-few-argumentsztype-error-keyword-argumentztype-error-multiple-valuesztype-error-star-starztype-error-starztype-error-operationztype-error-not-iterableztype-error-isinstanceztype-error-not-subscriptablezvalue-error-too-many-valueszvalue-error-too-few-valuesc               @   sb   e Zd ZdddZe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S )ErrorNc             C   s2   || _ || _|| _|d kr(t| j d }|| _d S )Nr   )path
_start_posnameCODESmessage)selfr   module_path	start_posr    r   d/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/jedi/inference/analysis.py__init__   s    zError.__init__c             C   s
   | j d S )Nr   )r   )r   r   r   r   line&   s    z
Error.linec             C   s
   | j d S )Nr   )r   )r   r   r   r   column*   s    zError.columnc             C   s"   | j jd }|tt| j d  S )Nr   )	__class____name__strr   r   )r   firstr   r   r   code.   s    z
Error.codec             C   s   d| j | j| j| j| jf S )Nz%s:%s:%s: %s %s)r   r    r!   r&   r   )r   r   r   r   __str__4   s    zError.__str__c             C   s$   | j |j ko"| j|jko"| j|jkS )N)r   r   r   )r   otherr   r   r   __eq__8   s    zError.__eq__c             C   s   |  | S )N)r)   )r   r(   r   r   r   __ne__<   s    zError.__ne__c             C   s   t | j| j| jfS )N)hashr   r   r   )r   r   r   r   __hash__?   s    zError.__hash__c             C   s&   d| j j| j| j| jd | jd f S )Nz<%s %s: %s@%s,%s>r   r   )r"   r#   r   r   r   )r   r   r   r   __repr__B   s    zError.__repr__)N)r#   
__module____qualname__r   propertyr    r!   r&   r'   r)   r*   r,   r-   r   r   r   r   r      s   
r   c               @   s   e Zd ZdS )WarningN)r#   r.   r/   r   r   r   r   r1   H   s   r1   c       
      C   sb   t | d }t| |||rd S |  }| }||||j|}	tjt|	dd | jj	
|	 |	S )Nr   F)format)r   _check_for_exception_catchget_root_contextZ
py__file__r   r   warningr$   inference_stateZanalysisappend)
node_contextZ
error_namenoder   typpayload	exceptionZmodule_contextr   Zissue_instancer   r   r   addL   s    r=   c                sV   |   }|j  dkrdS y  d }W n tk
r>   dS X t fdd|D S )zU
    Check if there's any setattr method inside an instance. If so, return True.
    NFsetattrc             3   sF   | ]>} j |j   k o jk n  o<|jjd ko:|jj|k V  qdS )ZfuncdefN)r   end_posparenttyper   ).0n)r9   r   r   	<genexpr>i   s   z%_check_for_setattr.<locals>.<genexpr>)r4   Z	tree_nodeZget_used_namesKeyErrorany)instancemoduleZ
stmt_namesr   )r9   r   _check_for_setattrZ   s    rI   c             C   sJ   d||f }t }| r,| s,t|r,t}||f}t| d|||| d S )Nz'AttributeError: %s has no attribute %s.zattribute-error)r   Zis_instanceZis_compiledrI   r1   r=   )Zname_contextZlookup_valuer   r   r:   r;   r   r   r   add_attribute_erroro   s    rJ   c                s   dd   fdd}fdd}}xt|dk	rt |tjtjfst |tjr|jdkrl|||rld	S |tkr|jd
kr||jd |jd rd	S |j}q.W dS )a  
    Checks if a jedi object (e.g. `Statement`) sits inside a try/catch and
    doesn't count as an error (if equal to `exception`).
    Also checks `hasattr` for AttributeErrors and uses the `payload` to compare
    it.
    Returns True if the exception was catched.
    c             S   s>   |   sdS x,| D ] }|  |jkr| j rdS qW dS )NFT)Zis_classmroZ
py__name__r#   Zparent_contextZis_builtins_module)clsr<   Z
python_clsr   r   r   check_match   s    
z/_check_for_exception_catch.<locals>.check_matchc                s   t | j}xD|D ]<}t| t|}|dkr|jj  k rF|jksn dS qW x|  D ]}|d krjdS |}xp|D ]h}ddlm} t	||j
r|jdkrx@| D ]$}	x|	 D ]}
 |
|rdS qW qW qz ||rzdS qzW qZW d S )NtryFTr   )iterabletuple)iterchildrennextr   r?   Zget_except_clause_testsZ
infer_nodeZjedi.inference.valuerO   
isinstanceSequenceZ
array_typeZ
py__iter__infer)objr<   iteratorZbranch_typesuiter9   Zexcept_classesrL   rO   
lazy_valuer:   )rM   	jedi_namer8   r   r   check_try_for_except   s*    






z8_check_for_exception_catch.<locals>.check_try_for_exceptc                sD  y&|j  j   kr|jk s$n t| jdks2t| jd }|jdkrP|jdksTt| jd }|jdkslt|jd }|jdkstddlm} |j|}t	|
 }t|d	kst|d \}}	t	|	 }
t|
dkrt|
d st|
d  d jks
t|d \}}	|	 }d |kS  tk
r>   d
S X d S )N)powerZ	atom_exprr   r   hasattrr   trailerarglist)TreeArgumentsr   F)r   r?   AssertionErrorrA   rR   valueZjedi.inference.argumentsra   r6   listunpacklenrV   r   Zget_safe_value)r9   rY   baser_   r`   ra   argsZunpacked_argskeyrZ   namesobjects)r[   r8   r;   r   r   check_hasattr   s,     


z1_check_for_exception_catch.<locals>.check_hasattrNZtry_stmtT)Zif_stmtZ
while_stmtr   r   F)	rT   r   FunctionClassZFlowrA   AttributeErrorrR   r@   )r8   r[   r<   r;   r\   rl   rW   r   )rM   r[   r8   r;   r   r3   ~   s    

r3   )N)__doc__Zparso.pythonr   Zjedir   Zjedi.inference.helpersr   ro   	NameErrorImportError	TypeError
ValueErrorr   r   r1   r=   rI   rJ   r3   r   r   r   r   <module>   s0   +