TL i`&xdZddlZddlZddlmZmZddlmZddlm Z ddl m Z m Z m Z ddlmZgdZej"d ej$ej"d ej$gZej"d Zdad Zd ZdZdZdZdZdZdZdZe dZe e dZ y)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:[^`]+:`([^`]+)`c^ttttfrtddlm}|atS)NrNumpyDocString) isinstance_numpy_doc_string_cache ImportError SyntaxErrornumpydoc.docscraper r s _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/inference/docstrings.py_get_numpy_doc_string_clsr/s')K+EF%%1, ""ctj5tjd t|jd} dddD]J\}}}||k(s t jd|}|r|jd}tt|cSgS#t $rgcYcdddSwxYw#1swYtxYw)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+8s  "h' 1.08EElSF $*1 Y >GA/0 0 1 I I   s(B=B## B:.B=9B::B==Cc#Ktj5tjd t|} ddd j d}||j dz }|D]\}}}|s|}t |Ed{y#t$r YdddywxYw#1swYexYw#t$rYywxYw79w)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' -+-f5C ""9-3##H--$++F"6*** +       +snCB#B C!B/)CB>C B B# CB  B##B,(C/ B;8C:B;;Cc#~Ktjd|r;|jdD]&}|jddj(ytjd|r|jddy|j drt |dj d}|jd k(r|t|j d d gD]^}|jd k(rd |jvrd%d*|jdk(s:d|jjvrd[d`yy|yw)z@ Attempts to interpret the possible types in `type_str` z\bor\borofrz\bof\b{z3.7)versionatomrchildrennumber.floatintstringbbytesstrN) rsearchsplitstrip startswithrr;typegetattrvalue string_prefixlower)type_strtnodeleafs rr#r#cs  yyH%% +A''$-"((* * + 9h 'nnT"1%%   S !Xu-66q9 99  a 0*bA $99(djj(% # YY(*d006688% #  $  s D D=.D=c  tDcgc]-}tj|tj|z/}}|D]2}|j |}|st |j dgcSt||Scc}w)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_PATTERNSrcompileescaperD_strip_rst_roler!r+)r$r%ppatternspatternr s r_search_param_in_docstrrYs&23 1ryy3343H35v& #EKKN34 45 ( ::3s2BcVtj|}|r|jdS|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 rrUrUs*  # #H -E {{1~rc|gStjd|}djd|D}|d|}tjd|d|j j } |j|d} |jd }|jd vrgSd d l m}|||j |g }tt!|j#|S#t$rgcYSwxYw#ttf$rgcYSwxYw)Nz((?:\w+\.)*\w+)\. c3&K|] }d| yw)zimport N).0rVs r z._infer_for_statement_string..sA!'! AszParse docstring code %sBLUEcolorF)error_recovery)namer: atom_exprr)DocstringModule)in_module_contextinference_state module_node code_lines)rfindalljoinrdbgrkgrammarrrr;AttributeError IndexErrorrHjedi.inference.docstring_utilsrir"_execute_types_in_stmt as_context) module_contextr@potential_importsimportsrqmodulestmtrir*s r_infer_for_statement_stringr|s ~  #7@iiA/@AAGy6( #F II'v>,,44Gve<r" yy55 ?(&66  A &q||~t< ==)   J ' s$)C=C, C)(C),D?Dcbj|}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). c3JK|]}tj|ywN)_execute_array_valuesrk)r`drws rraz)_execute_types_in_stmt..s&  n<.s )&os;)sr) jedi.inference.value.iterablerrrr array_type py__iter__rrinferappendr execute_annotation) rkarrayrrrvalues lazy_valueobjectsclss ` rrrs XW%-.53C3CGX3X**, 4J(()%++-)G MM/'2 3  4 !++w6iHOV,--''))rchfd}|jj}|jdk(rtS||j }|j r6|j dk(r#|||jj z}tjd|d|S)Nchtfdt|jjDS)Nc3DK|]}t|D]}|ywr)r|)r`r%rVrws rraz7infer_param..infer_docstring..s5 0K    s )rrYrgrJ) docstringrwparams rinfer_docstringz$infer_param..infer_docstrings. 4Y @P@PQ   rlambdef__init__z#Found param types for docstring: %srbrc) get_root_contextget_parent_functionrHr py__doc__is_bound_method py__name__ class_contextrrp)function_valuerrfunctypesrws ` @r infer_paramrs $446N  $ $ &D yyI N446 7E%%'))+z9 !=!=!G!G!IJJ II3U&I Lrc#Kd}||jD]$}t|j|Ed{&y7w)Nc3KtD]2}|j|}|st|jd4t |Ed{y7w)Nr)DOCSTRING_RETURN_PATTERNSrDrUr!r4)coderVr s rsearch_return_in_docstrz3infer_return_types..search_return_in_docstrsH* 6AHHTNE%ekk!n55 6 1666sA,A A A)rr|r)rrrMs rinfer_return_typesrsI7,N,D,D,FG\.~/N/N/PRZ[[[\[s:AAA)!__doc__rrparsorrjedirjedi.inference.cacherjedi.inference.base_valuerrr jedi.inference.lazy_valuer rRrSMrr[rrr+r4r#rYrUr|rurrrr_rrrs" *=5BJJ'.BJJ'. BJJ23#&+0B;8,">J *( * \  \r