o
    ˷eS                     @   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/ideatree/venv/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_context
py__file__r   r   warningr*   inference_stateanalysisappend)
node_context
error_namenoder   typpayload	exceptionmodule_contextr   issue_instancer   r   r   addL   s   rJ   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 )funcdefN)r   end_posparenttyper   ).0nrD   r   r   	<genexpr>i   s    
z%_check_for_setattr.<locals>.<genexpr>)r<   	tree_nodeget_used_namesKeyErrorany)instancemodule
stmt_namesr   rR   r   _check_for_setattrZ   s   r[   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   is_instanceis_compiledr[   r9   rJ   )name_contextlookup_valuer   r   rE   rF   r   r   r   add_attribute_erroro   s   r`   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mro
py__name__r)   parent_contextis_builtins_module)clsrG   
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   rM   get_except_clause_tests
infer_nodejedi.inference.valuerj   
isinstanceSequence
array_type
py__iter__infer)objrG   iteratorbranch_typesuiterD   except_classesrf   rj   
lazy_valuerE   )rh   	jedi_namerB   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)power	atom_exprr   r   hasattrr   trailerarglist)TreeArgumentsr   F)r   rM   rO   rm   valuejedi.inference.argumentsr   r?   listunpacklenrv   r   get_safe_valueAssertionError)rD   rz   baser   r   r   argsunpacked_argskeyr|   namesobjects)r}   rB   rF   r   r   check_hasattr   s.   "


z1_check_for_exception_catch.<locals>.check_hasattrNtry_stmtT)if_stmt
while_stmtr   r   F)	rr   r   FunctionClassFlowrO   AttributeErrorrm   rN   )rB   r}   rG   rF   r~   r   rw   r   )rh   r}   rB   rF   r   r;   ~   s   
r;   r.   )__doc__parso.pythonr   jedir   jedi.inference.helpersr   r   	NameErrorImportError	TypeError
ValueErrorr   r   r9   rJ   r[   r`   r;   r   r   r   r   <module>   s4    +