o
    ZhS                     @   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            	   
                  )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 u rt| j d }|| _d S )Nr   )path
_start_posnameCODESmessage)selfr   module_path	start_posr    r   N/var/www/html/lang_env/lib/python3.10/site-packages/jedi/inference/analysis.py__init__   s   
zError.__init__c                 C   
   | j d S Nr   r   r   r   r   r   line&      
z
Error.linec                 C   r!   )Nr   r#   r$   r   r   r   column*   r&   zError.columnc                 C   s"   | j jd }|tt| j d  S r"   )	__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 r.   )r1   r/   r   r   r   __ne__<   s   zError.__ne__c                 C   s   t | j| j| jfS r.   )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__r.   )r)   
__module____qualname__r    propertyr%   r'   r,   r-   r1   r2   r4   r5   r   r   r   r   r      s    



r   c                   @   s   e Zd ZdS )WarningN)r)   r6   r7   r   r   r   r   r9   H   s    r9   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   rE   c                    sV   |   }|j  du rdS z  d }W n
 ty   Y dS w t fdd|D S )zU
    Check if there's any setattr method inside an instance. If so, return True.
    NFsetattrc                 3   sH    | ]} 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rA   r   r   	<genexpr>i   s    
z%_check_for_setattr.<locals>.<genexpr>)r<   Z	tree_nodeZget_used_namesKeyErrorany)instancemoduleZ
stmt_namesr   rL   r   _check_for_setattrZ   s   rR   c                 C   sJ   d||f }t }| r| st|rt}||f}t| d|||| d S )Nz'AttributeError: %s has no attribute %s.r   )r   Zis_instanceZis_compiledrR   r9   rE   )Zname_contextZlookup_valuer   r   rB   rC   r   r   r   add_attribute_erroro   s   rS   c                    s   dd   fdd}fdd}}|dur[t |tjtjfs[t |tjrK|jdkr5|||r5d	S |tkrK|jd
v rK||jd |jd rKd	S |j}|dur[t |tjtjfr#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 | D ]}|  |jkr| j r dS q
dS )NFT)is_classmroZ
py__name__r)   Zparent_contextZis_builtins_module)clsrD   Z
python_clsr   r   r   check_match   s   z/_check_for_exception_catch.<locals>.check_matchc                    s   t | j}|D ]!}t| t|}|dkr(|jj  k r$|jks( dS   dS q|  D ]G}|d u r6 dS |}|D ]6}ddlm} t	||j
rj|jdkrj| D ]}	|	 D ]}
 |
|rg    dS qZqTq= ||rs  dS q=q-d S )NtryFTr   )iterabletuple)iterchildrennextr   rG   Zget_except_clause_testsZ
infer_nodeZjedi.inference.valuerY   
isinstanceSequenceZ
array_typeZ
py__iter__infer)objrD   iteratorZbranch_typesuiterA   Zexcept_classesrV   rY   
lazy_valuerB   )rW   	jedi_namer@   r   r   check_try_for_except   s<   




z8_check_for_exception_catch.<locals>.check_try_for_exceptc                    s>  z|j  j   kr|jk sJ  J | jdv sJ | jd }|jdkr(|jdks*J | jd }|jdks6J |jd }|jdksBJ ddlm} |j|}t|	 }t
|d	ks]J |d \}}	t|	 }
t
|
dkrut|
d swJ |
d  d jksJ |d \}}	|	 }d |v W S  ty   Y d
S w )N)powerZ	atom_exprr   r   hasattrr   trailerarglist)TreeArgumentsr   F)r   rG   rI   r\   valueZjedi.inference.argumentsrk   r>   listunpacklenr`   r   Zget_safe_valueAssertionError)rA   rc   baseri   rj   rk   argsZunpacked_argskeyrd   namesobjects)re   r@   rC   r   r   check_hasattr   s.   "


z1_check_for_exception_catch.<locals>.check_hasattrNZtry_stmtT)Zif_stmtZ
while_stmtr   r   F)	r^   r   FunctionClassZFlowrI   AttributeErrorr\   rH   )r@   re   rD   rC   rf   rv   ra   r   )rW   re   r@   rC   r   r;   ~   s   
r;   r.   )__doc__Zparso.pythonr   Zjedir   Zjedi.inference.helpersr   ry   	NameErrorImportError	TypeError
ValueErrorr   r   r9   rE   rR   rS   r;   r   r   r   r   <module>   s4    +