B
    7r\:                 @   s  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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e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)force_unicode)debug)CompiledObject)	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               @   sj   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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   5lib/python3.7/site-packages/jedi/evaluate/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    code0   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    __unicode__6   s    zError.__unicode__c             C   s   |   S )N)r)   )r   r   r   r    __str__:   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__=   s    zError.__eq__c             C   s   |  | S )N)r,   )r   r+   r   r   r    __ne__A   s    zError.__ne__c             C   s   t | j| j| jfS )N)hashr   r   r   )r   r   r   r    __hash__D   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__G   s    zError.__repr__)N)r%   
__module____qualname__r!   propertyr"   r#   r(   r)   r*   r,   r-   r/   r0   r   r   r   r    r      s   
r   c               @   s   e Zd ZdS )WarningN)r%   r1   r2   r   r   r   r    r4   M   s   r4   c       
      C   sb   t | d }t| |||rd S |  }| }||||j|}	tjt|	dd | jj	
|	 d S )Nr   F)format)r   _check_for_exception_catchget_root_contextZ
py__file__r   r   Zwarningr&   	evaluatorZanalysisappend)
node_contextZ
error_namenoder   typpayload	exceptionZmodule_contextr   instancer   r   r    addQ   s    r@   c                sd   ddl m} |  }t||s"dS |j y  d }W n tk
rL   dS X t fdd|D S )zU
    Check if there's any setattr method inside an instance. If so, return True.
    r   )ModuleContextFsetattrc             3   s,   | ]$} j |j   k o jk n  V  qd S )N)r   end_pos).0Zstmt)r;   r   r    	<genexpr>m   s   z%_check_for_setattr.<locals>.<genexpr>)jedi.evaluate.contextrA   r7   
isinstanceZ	tree_nodeZget_used_namesKeyErrorany)r?   rA   moduleZstmtsr   )r;   r    _check_for_setattr^   s    
rK   c       
      C   s   d||f }ddl m}m} t}t||rt|d|d }x(|D ] }t||rD|jjtkrDt	}P qDW t
|rtt	}||f}	t| d||||	 d S )Nz'AttributeError: %s has no attribute %s.r   )AbstractInstanceContextCompiledInstanceName__getattr____getattribute__zattribute-error)Zjedi.evaluate.context.instancerL   rM   r   rG   Zget_function_slot_namesZparent_contextobjobjectr4   rK   r@   )
Zname_contextZlookup_contextr   r   rL   rM   r<   Z
slot_namesnr=   r   r   r    add_attribute_errorq   s    


rS   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.   yt | to| |S  tk
r(   dS X d S )NF)rG   r   Zis_super_class	TypeError)clsr>   r   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   rC   Zget_except_clause_testsZ	eval_noderF   rX   rG   SequenceZ
array_typeZ
py__iter__infer)rP   r>   iteratorZbranch_typeZcolonsuiter;   Zexcept_classesrU   rX   lazy_contextr<   )rV   	jedi_namer:   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} t|j	|
 }t|d	kst|d \}}t| }	t|	dkrt|	d stt|	d  d jks
t|d \}}| }
d |
kS  tk
r>   d
S X d S )N)ZpowerZ	atom_exprr   r   hasattrr   trailerarglist)TreeArgumentsr   F)r   rC   AssertionErrortyper[   valueZjedi.evaluate.argumentsrg   listr8   Zunpacklenr^   r   r   Zget_safe_value)r;   r`   basere   rf   rg   argskeyra   namesZobjects)rb   r:   r=   r   r    check_hasattr   s*     


 z1_check_for_exception_catch.<locals>.check_hasattrNZtry_stmtT)Zif_stmtZ
while_stmtr   r	   F)	rG   r   ZFunctionZClassZFlowri   AttributeErrorr[   parent)r:   rb   r>   r=   rc   rq   rP   r   )rV   rb   r:   r=   r    r6      s    
r6   )N)__doc__Zparso.pythonr   Zjedi._compatibilityr   Zjedir   Zjedi.evaluate.compiledr   Zjedi.evaluate.helpersr   rr   	NameErrorImportErrorrT   
ValueErrorr   rQ   r   r4   r@   rK   rS   r6   r   r   r   r    <module>   s4   .