uBFjt&xdZddlZddlZddlmZmZddlmZddlm Z ddl m Z m Z m Z ddlmZgdZejd ejejd ejgZejd Zdad Zd ZdZdZdZdZdZdZdZe dZe e dZ dS)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 `_ - `Epydoc `_ - `Numpydoc `_ 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)parseParserSyntaxError)debug)inference_state_method_cache)iterator_to_value_setValueSet 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:[^`]+:`([^`]+)`cpttttfrtddlm}|atS)NrNumpyDocString) isinstance_numpy_doc_string_cache ImportError SyntaxErrornumpydoc.docscraper r s GC:\PYTHON\_runtimes\venv\Lib\site-packages\jedi/inference/docstrings.py_get_numpy_doc_string_clsr/s>)K+EFF&%%111111, ""ctj5tjd t|jd}n#t $rgcYcdddSwxYw dddn #1swxYwY|D]V\}}}||krJt jd|}|r|d}tt|cSWgS)zASearch `docstr` (in numpydoc format) for type(-s) of `param_str`.ignore ParametersNz"([^,]+(,[^,]+)*?)(,[ ]*optional)?$) warningscatch_warnings simplefilterr _parsed_data Exceptionrematchgrouplist_expand_typestr)docstr param_strparamsp_namep_typep_descrms r_search_param_in_numpydocstrr+8sa  " "h''' 1.0088ElSFF   II    $*11 Y  >GGA $//00 0 0 0  Is4A8"A  A8 A(A8'A((A88A<?A<c#Ktj5tjd t|}n#t$rYddddSwxYw dddn #1swxYwY |jd}||jdz }n#t$rYdSwxYw|D]\}}}|s|}t |Ed{V dS)zP Search `docstr` (in numpydoc format) for type(-s) of function returns. rNReturnsYields)rrrrrrr#)r$docreturnsr_namer_typer_descrs r_search_return_in_numpydocstrr4Ks  " "h''' -+--f55CC        "9-3#H-- #*++ F"6********** ++sFA-AA- AA-AA--A14A19B B%$B%c#Ktjd|rI|dD]1}|ddV2dStjd|r|ddVdS|drt |djd}|jd krlt|jd d gD]Q}|jd krd |j vrdVdV |jdkr$d|j vrdVKdVPdSdS|VdS)z@ Attempts to interpret the possible types in `type_str` z\bor\borofrz\bof\b{z3.13)versionatomrchildrennumber.floatintstringbbytesstrN) rsearchsplitstrip startswithrr;typegetattrvalue string_prefixlower)type_strtnodeleafs rr#r#cs  yH%%%% + +A''$--"((** * * * * + + 9h ' 'nnT""1%%%%%%   S ! !Xv...7: 9   a 0*bAA $ $9((dj((% # Y(**d0668888% #    $ $rcfdtD}|D]>}||}|r%t|dgcS?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'] cbg|]+}tj|tjz,S)rcompileescape).0pr%s r z+_search_param_in_docstr..sB333 1ry33344333rr)DOCSTRING_PARAM_PATTERNSrD_strip_rst_roler!r+)r$r%patternspatternr s ` r_search_param_in_docstrr]s$33331333H55v&&  5#EKKNN334 4 4 4 5 ( : ::rcht|}|r|dS|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!)rMr s rrZrZs4  # #H - -E {{1~~rc|gStjd|}dd|D}|d|}tjd|d|jj} ||d}n#t$rgcYSwxYw |j d }n#ttf$rgcYSwxYw|j d vrgSd d l m}|||j|g }tt!||S)Nz((?:\w+\.)*\w+)\. c3 K|] }d|V dS)zimport NrS)rVrWs r z._infer_for_statement_string..s(AA! ! AAAAAArzParse docstring code %sBLUEcolorF)error_recovery)namer: atom_exprr)DocstringModule)in_module_contextinference_state module_node code_lines)rfindalljoinrdbgrmgrammarrrr;AttributeError IndexErrorrHjedi.inference.docstring_utilsrkr"_execute_types_in_stmt as_context) module_contextr@potential_importsimportsrsmodulestmtrkr*s r_infer_for_statement_stringr~se ~  #7@@iiAA/@AAAAAG # #6 # #F I'v>>>>,4Gve<<  r" J '  y555 ?>>>>>(&6    A &q||~~t<< = ==s$$A<< B  B  BB32B3cn|}tjfd|DS)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). c3BK|]}tj|VdSN)_execute_array_valuesrm)rVdrys rrcz)_execute_types_in_stmt..sD  n.sA))&os;;))))))rrN) jedi.inference.value.iterablerrrr array_type py__iter__rrinferappendr execute_annotation) rmarrayrrrvalues lazy_valueobjectsclss ` rrrs XWWWWWWWWW%-.. .53CGX3X3X**,, 4 4J())))%++--)))G MM/'22 3 3 3 3 +w66iiHOV,,--''---rcfd}|}|jdkrtS||}|r=|dkr%|||jz}tj d|d|S)Ncjtfdt|jjDS)Nc3BK|]}t|D]}|VdSr)r~)rVr%rWrys rrcz7infer_param..infer_docstring..sX  0KK          r)rr]rirJ) docstringryparams rinfer_docstringz$infer_param..infer_docstringsJ    4Y @PQQ      rlambdef__init__z#Found param types for docstring: %srdre) get_root_contextget_parent_functionrHr py__doc__is_bound_method py__name__ class_contextrrr)function_valuerrfunctypesrys ` @r infer_paramrs      $4466N  $ $ & &D yI ON4466 7 7E%%''K))++z99 !=!G!G!I!IJJJ I3U&IIII Lrc#Kd}||D]*}t||Ed{V+dS)Nc3KtD]=}||}|r$t|dV>t |Ed{VdS)Nr)DOCSTRING_RETURN_PATTERNSrDrZr!r4)coderWr s rsearch_return_in_docstrz3infer_return_types..search_return_in_docstrsq* 6 6AHHTNNE 6%ekk!nn55555066666666666r)rr~r)rrrMs rinfer_return_typesrs}777,+N,D,D,F,FGG\\.~/N/N/P/PRZ[[[[[[[[[[\\r)!__doc__rrparsorrjedirjedi.inference.cacherjedi.inference.base_valuerrr jedi.inference.lazy_valuer rYrTMrr_rrr+r4r#r]rZr~rwrrrrSrrrs" ********======555555BJ'..BJ'.. BJ233###&+++0B;;;8,">">">J   ...( * \ \  \ \ \r