
    Mh`&                     x   d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZ g dZ ej        d	ej                   ej        d
ej                  gZ ej        d          Zdad Zd Zd Zd Zd Zd Zd Zd Zd Z e	            d             Z e	            ed                         Z dS )a  
Docstrings are another source of information for functions and classes.
:mod:`jedi.inference.dynamic_params` tries to find all executions of functions,
while the docstring parsing is much easier. There are three different types of
docstrings that |jedi| understands:

- `Sphinx <http://sphinx-doc.org/markup/desc.html#info-field-lists>`_
- `Epydoc <http://epydoc.sourceforge.net/manual-fields.html>`_
- `Numpydoc <https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`_

For example, the sphinx annotation ``:type foo: str`` clearly states that the
type of ``foo`` is ``str``.

As an addition to parameter searching, this module also provides return
annotations.
    N)parseParserSyntaxError)debug)inference_state_method_cache)iterator_to_value_setValueSet	NO_VALUES)LazyKnownValues)z\s*:type\s+%s:\s*([^\n]+)z\s*:param\s+(\w+)\s+%s:[^\n]*z\s*@type\s+%s:\s*([^\n]+)z\s*:rtype:\s*([^\n]+)z\s*@rtype:\s*([^\n]+)z:[^`]+:`([^`]+)`c                  p    t          t          t          t          f          rt          ddlm}  | at          S )Nr   NumpyDocString)
isinstance_numpy_doc_string_cacheImportErrorSyntaxErrornumpydoc.docscraper   r   s    Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/inference/docstrings.py_get_numpy_doc_string_clsr   /   s>    )K+EFF &%%111111,""    c                    t          j                    5  t          j        d           	  t                      |           j        d         }n# t
          $ r g cY cddd           S w xY w	 ddd           n# 1 swxY w Y   |D ]V\  }}}||k    rJt          j        d|          }|r|                    d          }t          t          |                    c S Wg S )zASearch `docstr` (in numpydoc format) for type(-s) of `param_str`.ignore
ParametersNz"([^,]+(,[^,]+)*?)(,[ ]*optional)?$   )warningscatch_warningssimplefilterr   _parsed_data	Exceptionrematchgrouplist_expand_typestr)docstr	param_strparamsp_namep_typep_descrms          r   _search_param_in_numpydocstrr+   8   sa   		 	"	"  h'''	 1.0088ElSFF 	 	 	II       	                $* 1 1Y>GGA $//00000	 
 Is4   A8"AA8A(A8'A((A88A<?A<c              #     K   t          j                    5  t          j        d           	  t                      |           }n# t          $ r Y ddd           dS w xY w	 ddd           n# 1 swxY w Y   	 |j        d         }||j        d         z  }n# t          $ r Y dS w xY w|D ]\  }}}|s|}t          |          E d{V   dS )zP
    Search `docstr` (in numpydoc format) for type(-s) of function returns.
    r   NReturnsYields)r   r   r   r   r   r   r#   )r$   docreturnsr_namer_typer_descrs         r   _search_return_in_numpydocstrr4   K   s      
	 	"	"  h'''	-+--f55CC 	 	 	       	                "9-3#H--   #* + + 	F"6**********	+ +sF   A-AA-
AA-AA--A14A19B 
B%$B%c              #     K   t          j        d|           rI|                     d          D ]1}|                    d          d                                         V  2dS t          j        d|           r|                     d          d         V  dS |                     d          rt          | d          j        d         }|j        d	k    rlt          |j        d
         dg           D ]Q}|j        dk    rd|j	        v rdV  dV   |j        dk    r$d|j
                                        v rdV  KdV  PdS dS | V  dS )z@
    Attempts to interpret the possible types in `type_str`
    z\bor\borofr   z\bof\b{z3.7)versionatomr   childrennumber.floatintstringbbytesstrN)r   searchsplitstrip
startswithr   r;   typegetattrvaluestring_prefixlower)type_strtnodeleafs       r   r#   r#   c   s     
 
yH%% %% 	+ 	+A''$--"((******	+ 	+ 
9h	'	' nnT""1%%%%%%			S	!	! Xu---6q99a 0*bAA 
$ 
$9((dj((%#Y(**d0668888%# 
$ 
$ r   c                     fdt           D             }|D ]>}|                    |           }|r%t          |                    d                    gc S ?t	          |           S )a  
    Search `docstr` for type(-s) of `param_str`.

    >>> _search_param_in_docstr(':type param: int', 'param')
    ['int']
    >>> _search_param_in_docstr('@type param: int', 'param')
    ['int']
    >>> _search_param_in_docstr(
    ...   ':type param: :class:`threading.Thread`', 'param')
    ['threading.Thread']
    >>> bool(_search_param_in_docstr('no document', 'param'))
    False
    >>> _search_param_in_docstr(':param int param: some description', 'param')
    ['int']

    c                 b    g | ]+}t          j        |t          j                  z            ,S  )r   compileescape).0pr%   s     r   
<listcomp>z+_search_param_in_docstr.<locals>.<listcomp>   sB     3 3 3 
1ry33344 3 3 3r   r   )DOCSTRING_PARAM_PATTERNSrD   _strip_rst_roler!   r+   )r$   r%   patternspatternr    s    `   r   _search_param_in_docstrr]      s    $3 3 3 313 3 3H 5 5v&& 	5#EKKNN334444	5 (	:::r   c                 h    t                               |           }|r|                    d          S | S )a  
    Strip off the part looks like a ReST role in `type_str`.

    >>> _strip_rst_role(':class:`ClassName`')  # strip off :class:
    'ClassName'
    >>> _strip_rst_role(':py:obj:`module.Object`')  # works with domain
    'module.Object'
    >>> _strip_rst_role('ClassName')  # do nothing when not ReST role
    'ClassName'

    See also:
    http://sphinx-doc.org/domains.html#cross-referencing-python-objects

    r   )REST_ROLE_PATTERNr    r!   )rM   r    s     r   rZ   rZ      s4     ##H--E {{1~~r   c                    |g S t          j        d|          }d                    d |D                       }| d| }t          j        d|d           | j        j        }	 |                    |d          }n# t          $ r g cY S w xY w	 |j	        d	         }n# t          t          f$ r g cY S w xY w|j        d
vrg S ddlm}  || | j        |g           }t          t!          |                                |                    S )Nz((?:\w+\.)*\w+)\.
c              3       K   | ]	}d | V  
dS )zimport NrS   )rV   rW   s     r   	<genexpr>z._infer_for_statement_string.<locals>.<genexpr>   s(      AA!!AAAAAAr   zParse docstring code %sBLUEcolorF)error_recovery)namer:   	atom_exprr   )DocstringModule)in_module_contextinference_statemodule_node
code_lines)r   findalljoinr   dbgrm   grammarr   r   r;   AttributeError
IndexErrorrH   jedi.inference.docstring_utilsrk   r"   _execute_types_in_stmt
as_context)	module_contextr@   potential_importsimportsrs   modulestmtrk   r*   s	            r   _infer_for_statement_stringr~      se   ~	
#7@@ iiAA/@AAAAAG##6##F	I'v>>>>,4Gve<<   			r"J'   			 y555	 ?>>>>>(&6		 	 	A &q||~~t<<===s$   $A< <B
BB B32B3c                 n                           |          }t          j         fd|D                       S )z
    Executing all types or general elements that we find in a statement. This
    doesn't include tuple, list and dict literals, because the stuff they
    contain is executed. (Used as type information).
    c              3   B   K   | ]}t          j        |          V  d S N)_execute_array_valuesrm   )rV   dry   s     r   rc   z)_execute_types_in_stmt.<locals>.<genexpr>   sD         	n<a@@     r   )
infer_noder   	from_sets)ry   r}   definitionss   `  r   rw   rw      sS     !++D11K         r   c                     ddl m}m}m} t	          ||          r|j        dv rg }|                                D ]V}t          j         fd|	                                D                       }|
                    t          |                     W|j        dk    r|n|} | |          hS |                                S )z
    Tuples indicate that there's not just one return value, but the listed
    ones.  `(str, int)` means that it returns a tuple with both types.
    r   )SequenceLiteralValue	FakeTupleFakeList)tupler"   c              3   8   K   | ]}t          |          V  d S r   )r   )rV   typrm   s     r   rc   z(_execute_array_values.<locals>.<genexpr>   sA       ) ) &os;;) ) ) ) ) )r   r   )jedi.inference.value.iterabler   r   r   r   
array_type
py__iter__r   r   inferappendr
   execute_annotation)	rm   arrayr   r   r   values
lazy_valueobjectsclss	   `        r   r   r      s   
 XWWWWWWWWW%-.. *53CGX3X3X**,, 	4 	4J( ) ) ) )%++--) ) )  G MM/'223333 +w66iiHOV,,--'')))r   c                    fd}|                                                                  }|j        dk    rt          S  ||                                           }|                                 r=|                                 dk    r%| || j                                                  z  }t          j	        d|d           |S )Nc                 j    t          fdt          | j        j                  D                       S )Nc              3   B   K   | ]}t          |          D ]}|V  d S r   )r~   )rV   r%   rW   ry   s      r   rc   z7infer_param.<locals>.infer_docstring.<locals>.<genexpr>   sX       
 
0KK
 
  
 
 
 
 
 
 
r   )r   r]   ri   rJ   )	docstringry   params    r   infer_docstringz$infer_param.<locals>.infer_docstring   sJ     
 
 
 
4Y
@PQQ
 
 
 
 
 	
r   lambdef__init__z#Found param types for docstring: %srd   re   )
get_root_contextget_parent_functionrH   r	   	py__doc__is_bound_method
py__name__class_contextr   rr   )function_valuer   r   functypesry   s    `   @r   infer_paramr      s    
 
 
 
 
 
 $4466N$$&&DyION446677E%%'' K))++z99!=!G!G!I!IJJJ	I3U&IIIILr   c              #      K   d } ||                                            D ]*}t          |                                 |          E d {V  +d S )Nc              3      K   t           D ]=}|                    |           }|r$t          |                    d                    V  >t	          |           E d {V  d S )Nr   )DOCSTRING_RETURN_PATTERNSrD   rZ   r!   r4   )coderW   r    s      r   search_return_in_docstrz3infer_return_types.<locals>.search_return_in_docstr  sq      * 	6 	6AHHTNNE 6%ekk!nn55555066666666666r   )r   r~   r   )r   r   rM   s      r   infer_return_typesr     s}      7 7 7 ,+N,D,D,F,FGG \ \.~/N/N/P/PRZ[[[[[[[[[[\ \r   )!__doc__r   r   parsor   r   jedir   jedi.inference.cacher   jedi.inference.base_valuer   r   r	   jedi.inference.lazy_valuer
   rY   rT   Mr   r_   r   r   r+   r4   r#   r]   rZ   r~   rw   r   r   r   rS   r   r   <module>r      s   " 
			  * * * * * * * *       = = = = = =          5 5 5 5 5 5    BJ'..BJ'.. 
 BJ233   # # #  &+ + +0  B; ; ;8  ,"> "> ">J
 
 
* * *(    * 
\ 
\   
\ 
\ 
\r   