
    BNe                         d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ e	rddlZg dZ G d d          Z G d d          ZddZddZdS )z
Helpers for retrieving the function signature of the function call that we are
editing.

Either with the Jedi library, or using `inspect.signature` if Jedi fails and we
can use `eval()` to evaluate the function object.
    )annotationsN)	Signature)_ParameterKind)TYPE_CHECKINGAnyDictListOptionalSequenceTuple)Document   )DictionaryCompleter)get_jedi_script_from_document)r   get_signatures_using_jediget_signatures_using_evalc                  6    e Zd Zdd
ZddZedd            ZdS )	Parameternamestr
annotation
str | NonedefaultkindParameterKindreturnNonec                >    || _         || _        || _        || _        d S N)r   r   r   r   )selfr   r   r   r   s        }/home/feoh/.cache/pypoetry/virtualenvs/veilid-python-play-bIboZq2W-py3.11/lib/python3.11/site-packages/ptpython/signatures.py__init__zParameter.__init__   s$     		$    c                    d| j         dS )NzParameter(name=))r   r    s    r!   __repr__zParameter.__repr__(   s    /////r#   c                <    | j         }| j        |d| j         z  }|S )z$
        Name + annotation.
        Nz: )r   r   )r    descriptions     r!   r)   zParameter.description+   s.    
 i?&1111Kr#   N)
r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__r"   r'   propertyr)    r#   r!   r   r      s\           0 0 0 0 	 	 	 X	 	 	r#   r   c                  Z    e Zd ZdZ	 	 	 dddZedd            Zedd            ZddZdS )r   a  
    Signature definition used wrap around both Jedi signatures and
    python-inspect signatures.

    :param index: Parameter index of the current cursor position.
    :param bracket_start: (line, column) tuple for the open bracket that starts
        the function call.
    N r   r   r   r   	docstring
parametersSequence[Parameter]index
int | Nonereturnsbracket_starttuple[int, int]r   r   c                Z    || _         || _        || _        || _        || _        || _        d S r   r   r3   r4   r6   r8   r9   )r    r   r3   r4   r6   r8   r9   s          r!   r"   zSignature.__init__B   s5     	"$
*r#   	signatureInspectSignatureintc           
     :   g }d	d}|j                                         D ]l}|                    t          |j         ||j                  |j        t          j        j        urt          |j                  nd |j
                             m | ||||d          S )
Nr   objectr   r   c                    	 t          | j                  S # t          $ r Y nw xY wt          |           } |                     d          r| t	          d          d         } | S )zJ
            Get annotation as string from inspect signature.
            ztyping.ztyping:N)r   r+   AttributeError
startswithlen)r   s    r!   get_annotation_namez=Signature.from_inspect_signature.<locals>.get_annotation_name\   sw    :.///!    ZJ$$Y// :'I(8(89
s    
##r   r   r   r   r1   )r   r3   r4   r6   r8   )r   rA   r   r   )r4   valuesappendr   r   r   r   inspectemptyreprr   )clsr   r3   r=   r6   r4   rF   ps           r!   from_inspect_signaturez Signature.from_inspect_signatureR   s     
	 	 	 	 %,,.. 
	 
	A221<@@y(9(??? !OOO  	 	 	 	 s!
 
 
 	
r#   jedi.api.classes.Signaturec           	     V   g }|j         D ]B}||                    t          |                                d d |j                             C|                                }t          |t                    s|                    d          } | |j	        |||j
        d|j                  S )NrG   zutf-8r1   r<   )paramsrI   r   	to_stringr   r3   
isinstancer   decoder   r6   r9   )rM   r=   r4   rN   r3   s        r!   from_jedi_signaturezSignature.from_jedi_signature   s    
! 	 	Ay# 	      ''))	)S)) 	2!((11Is!/#1
 
 
 	
r#   c                (    d| j         d| j        dS )Nz
Signature(z, parameters=r%   )r   r4   r&   s    r!   r'   zSignature.__repr__   s    JDIJJdoJJJJr#   )Nr1   r2   )r   r   r3   r   r4   r5   r6   r7   r8   r   r9   r:   r   r   )
r   r   r3   r   r=   r>   r6   r?   r   r   )r=   rP   r   r   r*   )	r+   r,   r-   __doc__r"   classmethodrO   rV   r'   r/   r#   r!   r   r   8   s          !)/+ + + + +  *
 *
 *
 [*
X 
 
 
 [
<K K K K K Kr#   r   documentr   localsdict[str, Any]globalsr   list[Signature]c                    t          | ||          }|sg S 	 |                                }	 |r|d         j         n/# t          $ r Y n#w xY w# t          $ r g }Y nt
          $ r g }Y nw xY wd |D             S )Nr   c                B    g | ]}t                               |          S r/   )r   rV   ).0sigs     r!   
<listcomp>z-get_signatures_using_jedi.<locals>.<listcomp>   s&    EEE3I))#..EEEr#   )r   get_signaturesrR   rC   
ValueError	Exception)rZ   r[   r]   script
signaturess        r!   r   r      s     +8VWEEF  	**,,
 	 %1$$ 	 	 	D	%    


    


	$ FE*EEEEs&   A < 
A	A	A(A('A(c                   | j         }| j        dz
  }dddd}dg}d}d}|dk    r| j        |         }	|	d	v r|                    |	           nc|	d
v rA|sng||d                  |	k    rnT|                                 t          |          dk    rd}n*n|	dk    rt          |          dk    r|dz  }|dz  }|dk    |sg S t          fdfd                              t          | j        |                    }
|
g S 	 |
j	        }n# t          $ r |
j        j	        }Y nw xY w	 t          j        |
          }n# t          $ r g cY S t          $ r g cY S w xY w	 |
j        pd}n	#  d}Y nxY wt"                              ||||          gS )z
    Look for the signature of the function before the cursor position without
    use of Jedi. This uses a similar approach as the `DictionaryCompleter` of
    running `eval()` over the detected function name.
    r   ({[)r%   }]r%   r   Fz)]}z([{T,c                      S r   r/   )r]   s   r!   <lambda>z+get_signatures_using_eval.<locals>.<lambda>   s    g r#   c                      S r   r/   )r[   s   r!   rr   z+get_signatures_using_eval.<locals>.<lambda>   s    v r#   )cursor_positionNr1   )r6   )text_before_cursorrt   textrI   poprE   r   eval_expressionr   r+   rf   	__class__rJ   r=   	TypeErrorre   rX   r   rO   )rZ   r[   r]   rv   posparen_mappingparen_stackcomma_countfound_startcharobjr   r=   docs    ``           r!   r   r      s=    &D

"Q
&CCc22MK KK
((}S!5==t$$$$U]]  [_-55OO;1$$" % S[[S--221Kq/ ((2  	
 oooo~~~~
>
>
N
N444f C {	&| & & &}%&%c**		   			   			kR ,,T3	,UUVVs6   D D$#D$(D= =EEE	E' 'E-)rZ   r   r[   r\   r]   r\   r   r^   )rX   
__future__r   rJ   r   r>   r   r   typingr   r   r   r	   r
   r   r   prompt_toolkit.documentr   	completerr   utilsr   jedi.api.classesjedi__all__r   r   r   r/   r#   r!   <module>r      s    # " " " " "  1 1 1 1 1 1 3 3 3 3 3 3 L L L L L L L L L L L L L L L L L L , , , , , , * * * * * * 0 0 0 0 0 0 
Q
Q
Q       <gK gK gK gK gK gK gK gKT F  F  F  FFJW JW JW JW JW JWr#   