Format: application/x-python-code
⬇ Download File (8.7 KB)
   1  o
   2  
   3  �h`&�@s�dZddlZddlZddlmZmZddlmZddlm	Z	ddl
   4  mZmZm
   5  Z
   6  ddlmZgd�Ze�d	ej�e�d
   7  ej�gZe�d�Zdadd
   8  �Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze	�dd��Ze	�ed d!���Z dS)"a�
   9  Docstrings are another source of information for functions and classes.
  10  :mod:`jedi.inference.dynamic_params` tries to find all executions of functions,
  11  while the docstring parsing is much easier. There are three different types of
  12  docstrings that |jedi| understands:
  13  
  14  - `Sphinx <http://sphinx-doc.org/markup/desc.html#info-field-lists>`_
  15  - `Epydoc <http://epydoc.sourceforge.net/manual-fields.html>`_
  16  - `Numpydoc <https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`_
  17  
  18  For example, the sphinx annotation ``:type foo: str`` clearly states that the
  19  type of ``foo`` is ``str``.
  20  
  21  As an addition to parameter searching, this module also provides return
  22  annotations.
  23  �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:[^`]+:`([^`]+)`cCs&ttttf�r	t�ddlm}|atS)Nr��NumpyDocString)�
  24  isinstance�_numpy_doc_string_cache�ImportError�SyntaxErrorZnumpydoc.docscraperr
  25  �r�Oc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/docstrings.py�_get_numpy_doc_string_cls/s
  26  rc	Cs�t���*t�d�z
  27  t�|�jd}Wnty&gYWd�SwWd�n1s1wY|D]\}}}||krVt�d|�}|rN|�d�}t	t
  28  |��Sq8gS)zASearch `docstr` (in numpydoc format) for type(-s) of `param_str`.�ignoreZ
  29  ParametersNz"([^,]+(,[^,]+)*?)(,[ ]*optional)?$�)�warnings�catch_warnings�simplefilterr�_parsed_data�	Exception�re�match�group�list�_expand_typestr)�docstr�	param_str�paramsZp_name�p_typeZp_descr�mrrr�_search_param_in_numpydocstr8s$
  30  
  31  ���
  32  �r$c	cs��t���%t�d�zt�|�}Wnty"YWd�dSwWd�n1s-wYz|jd}||jd7}Wn
  33  tyJYdSw|D]\}}}|sV|}t|�EdHqMdS)zP
  34      Search `docstr` (in numpydoc format) for type(-s) of function returns.
  35      rNZReturnsZYields)rrrrrrr)r�doc�returnsZr_nameZr_typeZr_descrrrr�_search_return_in_numpydocstrKs,�
  36  
  37  ���
  38  ��r'ccs��t�d|�r|�d�D]}|�d�d��VqdSt�d|�r+|�d�dVdS|�d�rst|dd�jd}|jd	krot|jd
  39  dg�D])}|jdkr[d
  40  |j	vrWdVqGdVqG|jdkrnd|j
  41  ��vrkdVqGdVqGdSdS|VdS)z@
  42      Attempts to interpret the possible types in `type_str`
  43      z\bor\b�orZofrz\bof\b�{z3.7)�version�atomr�children�number�.�float�int�string�b�bytes�strN)r�search�split�strip�
  44  startswithrr,�type�getattr�valueZ
  45  string_prefix�lower)�type_str�t�node�leafrrrrcs.��
  46  
  47  
  48  
  49  
  50  ��
  51  rcsH�fdd�tD�}|D]}|�|�}|rt|�d��gSqt|��S)a�
  52      Search `docstr` for type(-s) of `param_str`.
  53  
  54      >>> _search_param_in_docstr(':type param: int', 'param')
  55      ['int']
  56      >>> _search_param_in_docstr('@type param: int', 'param')
  57      ['int']
  58      >>> _search_param_in_docstr(
  59      ...   ':type param: :class:`threading.Thread`', 'param')
  60      ['threading.Thread']
  61      >>> bool(_search_param_in_docstr('no document', 'param'))
  62      False
  63      >>> _search_param_in_docstr(':param int param: some description', 'param')
  64      ['int']
  65  
  66      cs g|]}t�|t�����qSr)r�compile�escape��.0�p�r rr�
  67  <listcomp>�s�z+_search_param_in_docstr.<locals>.<listcomp>r)�DOCSTRING_PARAM_PATTERNSr5�_strip_rst_rolerr$)rr �patterns�patternrrrFr�_search_param_in_docstr�s
  68  �
  69  �
  70  rLcCst�|�}|r|�d�S|S)a�
  71      Strip off the part looks like a ReST role in `type_str`.
  72  
  73      >>> _strip_rst_role(':class:`ClassName`')  # strip off :class:
  74      'ClassName'
  75      >>> _strip_rst_role(':py:obj:`module.Object`')  # works with domain
  76      'module.Object'
  77      >>> _strip_rst_role('ClassName')  # do nothing when not ReST role
  78      'ClassName'
  79  
  80      See also:
  81      http://sphinx-doc.org/domains.html#cross-referencing-python-objects
  82  
  83      r)�REST_ROLE_PATTERNrr)r=rrrrrI�s
  84  
  85  rIc		Cs�|durgSt�d|�}d�dd�|D��}|�d|��}tjd|dd�|jj}z	|j|dd	�}Wnty=gYSwz|j	d
  86  }Wn
  87  t
  88  tfyRgYSw|jdvrZgSdd
  89  l
  90  m}|||j|gd�}tt|��|��S)Nz((?:\w+\.)*\w+)\.�
  91  css�|]}d|��VqdS)zimport NrrCrrr�	<genexpr>�s�z._infer_for_statement_string.<locals>.<genexpr>zParse docstring code %s�BLUE��colorF)Zerror_recovery�����)�namer+Z	atom_exprr)�DocstringModule)Zin_module_context�inference_stateZmodule_nodeZ
  92  code_lines)r�findall�joinr�dbgrV�grammarrrr,�AttributeError�
  93  IndexErrorr9Zjedi.inference.docstring_utilsrUr�_execute_types_in_stmtZ
  94  as_context)	�module_contextr1Zpotential_importsZimportsrZ�module�stmtrUr#rrr�_infer_for_statement_string�s6��
  95  �racs"��|�}t��fdd�|D��S)z�
  96      Executing all types or general elements that we find in a statement. This
  97      doesn't include tuple, list and dict literals, because the stuff they
  98      contain is executed. (Used as type information).
  99      c3s�|]	}t�j|�VqdS�N)�_execute_array_valuesrV)rD�d�r^rrrO�s
 100  �
 101  �
 102  �z)_execute_types_in_stmt.<locals>.<genexpr>)Z
 103  infer_noder�	from_sets)r^r`Zdefinitionsrrerr]�s
 104  �r]c	s�ddlm}m}m}t||�rA|jdvrAg}|��D]}t��fdd�|�	�D��}|�
 105  t|��q|jdkr9|n|}|�|�hS|��S)z�
 106      Tuples indicate that there's not just one return value, but the listed
 107      ones.  `(str, int)` means that it returns a tuple with both types.
 108      r)�SequenceLiteralValue�	FakeTuple�FakeList)�tuplerc3s�|]}t�|�VqdSrb)rc)rD�typ�rVrrrO�s
 109  ��
 110  �z(_execute_array_values.<locals>.<genexpr>rj)
 111  Zjedi.inference.value.iterablergrhrirZ
 112  array_typeZ
 113  py__iter__rrfZinfer�appendr	Zexecute_annotation)	rV�arrayrgrhri�valuesZ
 114  lazy_value�objects�clsrrlrrc�s�rccsr��fdd�}|������}|jdkrtS||���}|��r/|��dkr/|||j���O}tj	d|dd�|S)Ncs t�fdd�t|�jj�D��S)Nc3s$�|]
 115  }t�|�D]}|Vq	qdSrb)ra)rDr rErerrrO�s����z7infer_param.<locals>.infer_docstring.<locals>.<genexpr>)rrLrTr;)�	docstring�r^�paramrr�infer_docstring�s�z$infer_param.<locals>.infer_docstringZlambdef�__init__z#Found param types for docstring: %srPrQ)
 116  �get_root_contextZget_parent_functionr9r�	py__doc__Zis_bound_methodZ
 117  py__name__Z
 118  class_contextrrY)�function_valuertru�func�typesrrsr�infer_param�s
 119  r|ccs4�dd�}||���D]}t|��|�EdHqdS)Ncss<�tD]}|�|�}|rt|�d��Vqt|�EdHdS)Nr)�DOCSTRING_RETURN_PATTERNSr5rIrr')�coderErrrr�search_return_in_docstrs�
 120  �z3infer_return_types.<locals>.search_return_in_docstr)rxrarw)ryrr=rrr�infer_return_typess
 121  ��r�)!�__doc__rrZparsorrZjedirZjedi.inference.cacherZjedi.inference.base_valuerrrZjedi.inference.lazy_valuer	rHrA�Mr}rMr
 122  rr$r'rrLrIrar]rcr|r�rrrr�<module>s8�
 123  	!%
 124  
 125