
    -h`&                     x   S r SSKrSSKrSSKJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SSKJr  / SQr\R"                  " S	\R$                  5      \R"                  " S
\R$                  5      /r\R"                  " S5      rSqS rS rS rS rS rS rS rS rS r\	" 5       S 5       r\	" 5       \S 5       5       r g)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                  h    [        [        [        [        45      (       a  [        eSSKJn   U q[        $ )Nr   NumpyDocString)
isinstance_numpy_doc_string_cacheImportErrorSyntaxErrornumpydoc.docscraper   r   s    lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\jedi/inference/docstrings.py_get_numpy_doc_string_clsr   /   s*    )K+EFF%%1,""    c                    [         R                  " 5          [         R                  " S5         [        5       " U 5      R                  S   n SSS5        W HP  u  p4nX1:X  d  M  [        R                  " SU5      nU(       a  UR                  S5      n[        [        U5      5      s  $    / $ ! [
         a    / s sSSS5        $ f = f! , (       d  f       N= f)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   s    		 	 	"h'	 /08EElSF 
# $*>GA/00 $* I  	I 
#	"	 
#	"s(   CB,,C8CCC
Cc              #     #    [         R                  " 5          [         R                  " S5         [        5       " U 5      n SSS5         WR
                  S   nX!R
                  S   -  nU H"  u  p4nU(       d  Un[        U5       Sh  vN   M$     g! [         a     SSS5        gf = f! , (       d  f       Np= f! [         a     gf = f NB7f)zH
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5C 
# ""9-##H-- $+F"6***	 $+  	 
#	"		 
#	"   	+so   CB+BC
 B< *C	C
	C
B(B+	C'B((B++
B95C<
C	CC		Cc              #     #    [         R                  " SU 5      (       a=  U R                  S5       H'  nUR                  S5      S   R                  5       v   M)     g[         R                  " SU 5      (       a  U R                  S5      S   v   gU R	                  S5      (       a  [        U SS9R                  S   nUR                  S	:X  a  [        UR                  S
   S/ 5       Hi  nUR                  S:X  a  SUR                  ;   a  Sv   M)  Sv   M/  UR                  S:X  d  MA  SUR                  R                  5       ;   a  Sv   Me  Sv   Mk     ggU v   g7f)z8
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    
 
yyH%%%A''$-"((** & 
9h	'	'nnT"1%%			S	!	!Xu-66q999a 0*bA99(djj(%#YY(*d006688%# B   s   D!E'3Ec           	          [          Vs/ s H0  n[        R                  " U[        R                  " U5      -  5      PM2     nnU H8  nUR	                  U 5      nU(       d  M  [        UR                  S5      5      /s  $    [        X5      $ s  snf )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']

r   )DOCSTRING_PARAM_PATTERNSr   compileescaperD   _strip_rst_roler!   r+   )r$   r%   ppatternspatternr    s         r   _search_param_in_docstrrY      s    & 231A 

1ryy3341  3v&5#EKKN344 
 (::3s   7Bc                 `    [         R                  U 5      nU(       a  UR                  S5      $ U $ )ax  
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   rU   rU      s*     ##H-E{{1~r   c                    Uc  / $ [         R                  " SU5      nSR                  S U 5       5      nU SU 3n[        R                  " SUSS9  U R
                  R                  n UR                  USS9n UR                  S	   nUR                  S
;  a  / $ SSKJn  U" U U R
                  U/ S9n[        [!        UR#                  5       U5      5      $ ! [         a    / s $ f = f! [        [        4 a    / s $ f = f)Nz((?:\w+\.)*\w+)\.
c              3   ,   #    U  H
  nS U 3v   M     g7f)zimport N ).0rV   s     r   	<genexpr>._infer_for_statement_string.<locals>.<genexpr>   s     A/@!'!/@s   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   dbgrl   grammarr   r   r;   AttributeError
IndexErrorrH   jedi.inference.docstring_utilsrj   r"   _execute_types_in_stmt
as_context)	module_contextr@   potential_importsimportsrr   modulestmtrj   r*   s	            r   _infer_for_statement_stringr}      s   ~	

#7@ iiA/@AAGy6(#F	II'v>,,44Gve<r" yy55	 ?(&66		A &q||~t<==)  	
 J' 	s$   )C :C) C&%C&)C>=C>c                 f   ^  T R                  U5      n[        R                  " U 4S jU 5       5      $ )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   P   >#    U  H  n[        TR                  U5      v   M     g 7fN)_execute_array_valuesrl   )r`   drx   s     r   ra   )_execute_types_in_stmt.<locals>.<genexpr>   s(      A 	n<<a@@   #&)
infer_noder   	from_sets)rx   r|   definitionss   `  r   rv   rv      s5     !++D1K   r   c                 v  ^  SSK JnJnJn  [	        X5      (       a  UR
                  S;   a  / nUR                  5        HK  n[        R                  " U 4S jUR                  5        5       5      nUR                  [        U5      5        MM     UR
                  S:X  a  UOUnU" T U5      1$ UR                  5       $ )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   <   >#    U  H  n[        TU5      v   M     g 7fr   )r   )r`   typrl   s     r   ra   (_execute_array_values.<locals>.<genexpr>   s"      )-C &os;;-s   r   )jedi.inference.value.iterabler   r   r   r   
array_type
py__iter__r   r   inferappendr
   execute_annotation)	rl   arrayr   r   r   values
lazy_valueobjectsclss	   `        r   r   r      s    
 XW%..53C3CGX3X**,J(( )%++-) G MM/'23 - !++w6iHOV,--''))r   c                 r  ^^ UU4S jnU R                  5       mTR                  5       nUR                  S:X  a  [        $ U" U R	                  5       5      nU R                  5       (       a6  U R                  5       S:X  a"  XB" U R                  R	                  5       5      -  n[        R                  " SUSS9  U$ )Nc                 j   > [        U4S j[        U TR                  R                  5       5       5      $ )Nc              3   P   >#    U  H  n[        TU5        H  nUv   M	     M     g 7fr   )r}   )r`   r%   rV   rx   s      r   ra   7infer_param.<locals>.infer_docstring.<locals>.<genexpr>   s,      
Q	0K K Qr   )r   rY   rh   rJ   )	docstringrx   params    r   infer_docstring$infer_param.<locals>.infer_docstring   s.     
4Y

@P@PQ
 
 	
r   lambdef__init__z#Found param types for docstring: %src   rd   )
get_root_contextget_parent_functionrH   r	   	py__doc__is_bound_method
py__name__class_contextr   rq   )function_valuer   r   functypesrx   s    `   @r   infer_paramr      s    
 $446N$$&DyyIN4467E%%''))+z9!=!=!G!G!IJJ	II3U&ILr   c              #      #    S nU" U R                  5       5       H%  n[        U R                  5       U5       S h  vN   M'     g  N	7f)Nc              3      #    [          H9  nUR                  U 5      nU(       d  M  [        UR                  S5      5      v   M;     [	        U 5       S h  vN   g  N7f)Nr   )DOCSTRING_RETURN_PATTERNSrD   rU   r!   r4   )coderV   r    s      r   search_return_in_docstr3infer_return_types.<locals>.search_return_in_docstr  sD     *AHHTNEu%ekk!n55 +
 1666s    A.AAA)r   r}   r   )r   r   rM   s      r   infer_return_typesr     sB     7 ,N,D,D,FG.~/N/N/PRZ[[[ H[s   :AA
A)!__doc__r   r   parsor   r   jedir   jedi.inference.cacher   jedi.inference.base_valuer   r   r	   jedi.inference.lazy_valuer
   rR   rS   Mr   r[   r   r   r+   r4   r#   rY   rU   r}   rv   r   r   r   r_   r   r   <module>r      s   " 
  *  =  5  JJ'.JJ'. 
 JJ23   #&+0B;8,">J
*(   * 
\   
\r   