TL isddZddlZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z dd l mZdd lmZdd lmZmZdd lmZdd lmZmZddlmZmZddlmZddlmZddl m!Z!dZ"dZ#dZ$GddZ%Gdde%Z&Gdde%Z'Gdde'Z(Gdde(Z)Gdd e'Z*y)!a` There are a couple of classes documented in here: - :class:`.BaseName` as an abstact base class for almost everything. - :class:`.Name` used in a lot of places - :class:`.Completion` for completions - :class:`.BaseSignature` as a base class for signatures - :class:`.Signature` for :meth:`.Script.get_signatures` only - :class:`.ParamName` used for parameters of signatures - :class:`.Refactoring` for refactorings - :class:`.SyntaxError` for :meth:`.Script.get_syntax_errors` only These classes are the much biggest part of the API, because they contain the interesting information about all operations. N)Path)Optional)search_ancestor)settings)debug)unite)memoize_method) MixedName) ImportName SubModuleName)StubModuleValue) convert_namesconvert_values)ValueSet HasNoContext) KeywordName)completion_cache)filter_follow_importsct|dS)Nc"|jxsdSNrr) start_posss V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/api/classes.pyz*_sort_names_by_start_pos..%sq{{'d!ddddd"d#Z ej>d$ddd%d&Z!d'Z"d(Z#d0d)Z$d1d*Z%d+Z&d,Z'd-Z(y.)2BaseNamezI The base class for all definitions, completions and signatures. zos.pathosio functools collectionssocketsqlite3) posixpath riscospathntpath os2emxpathmacpath genericpathposix_io _functools _collections_socket_sqlite3c#ZK|]#\}}t|jd|f%yw).N)tuplesplit).0kvs r zBaseName.Os*v15.2s)+zargparse._ActionsContainerzargparse.ArgumentParserc`||_||_ t|jt|_yr2)_inference_state_name isinstancer is_keyword)selfr*r.s r__init__zBaseName.__init__Ss* /  %TZZ=rc6|jjSr2)rSget_root_contextrVs r_get_module_contextzBaseName._get_module_context[s zz**,,rreturnc|j}|js|js |jj}|Sy)zT Shows the file path of a module. e.g. ``/usr/lib/python3.9/os.py`` N)r[is_stub is_compiled py__file__)rVmodulepaths r module_pathzBaseName.module_pathbsH ))+ >> 6#5#5#7$(#;#;#=#H#H#JDKrc6|jjS)z Name of variable/function/class/module. For example, for ``x = None`` it returns ``'x'``. :rtype: str or None )rSget_public_namerZs rr.z BaseName.namepszz))++rcX|jj}d}|3|j}|!|jdk(r|j rd}t |jt s|r,|jjD]}|jcS|jjS)a The type of the definition. Here is an example of the value of this attribute. Let's consider the following source. As what is in ``variable`` is unambiguous to Jedi, :meth:`jedi.Script.infer` should return a list of definition for ``sys``, ``f``, ``C`` and ``x``. >>> from jedi import Script >>> source = ''' ... import keyword ... ... class C: ... pass ... ... class D: ... pass ... ... x = D() ... ... def f(): ... pass ... ... for variable in [keyword, f, C, x]: ... variable''' >>> script = Script(source) >>> defs = script.infer() Before showing what is in ``defs``, let's sort it by :attr:`line` so that it is easy to relate the result to the source code. >>> defs = sorted(defs, key=lambda d: d.line) >>> print(defs) # doctest: +NORMALIZE_WHITESPACE [, , , ] Finally, here is what you can get from :attr:`type`: >>> defs = [d.type for d in defs] >>> defs[0] 'module' >>> defs[1] 'class' >>> defs[2] 'instance' >>> defs[3] 'function' Valid values for type are ``module``, ``class``, ``instance``, ``function``, ``param``, ``path``, ``keyword``, ``property`` and ``statement``. F import_fromT) rS tree_nameget_definitiontype is_definitionrTr inferapi_type)rVrhresolve definitionr+s rrjz BaseName.type{srJJ((   "113J%*//]*J++- djj- 0G))+ &~~% &zz"""rc>|jjS)aP The module name, a bit similar to what ``__name__`` is in a random Python module. >>> from jedi import Script >>> source = 'import json' >>> script = Script(source, path='example.py') >>> d = script.infer()[0] >>> print(d.module_name) # doctest: +ELLIPSIS json )r[ py__name__rZs r module_namezBaseName.module_names'')4466rc|jj}t|trt d|j DS|j S)z< Returns True, if this is a builtin module. c3<K|]}|jywr2)r_)rMrOs rrPz-BaseName.in_builtin_module..sI1q}}I)r[ get_valuerTr anynon_stub_value_setr_)rVr+s rin_builtin_modulezBaseName.in_builtin_modulesK((*446 e_ -I0H0HII I  ""rc>|jj}|y|dS)z7The line where the definition occurs (starting with 1).NrrSrrVrs rlinez BaseName.line&JJ((  |rc>|jj}|y|dS)z9The column where the definition occurs (starting with 0).Nr{r|s rcolumnzBaseName.columnr~rc|jjy|jjj}||jjS|jS)z The (row, column) of the start of the definition range. Rows start with 1, columns start with 0. :rtype: Optional[Tuple[int, int]] N)rSrhrir)rVros rget_definition_start_positionz&BaseName.get_definition_start_positionsQ ::   'ZZ))88:  ::'' '###rcz|jjy|jjj}| |jjjS|jdvrE|j }|jdk(r|j jS|jS|jS)z The (row, column) of the end of the definition range. Rows start with 1, columns start with 0. :rtype: Optional[Tuple[int, int]] N)functionclassnewline)rSrhriend_posrj get_last_leafget_previous_leaf)rVro last_leafs rget_definition_end_positionz$BaseName.get_definition_end_positions ::   'ZZ))88:  ::''// / 99- -"002I~~* 224<<<$$ $!!!rFct|jtr|ry|j}|r|S|j }|r |r|dz|zS||zS)ai Return a document string for this completion object. Example: >>> from jedi import Script >>> source = '''\ ... def f(a, b=1): ... "Document for function f." ... ''' >>> script = Script(source, path='example.py') >>> doc = script.infer(1, len('def f'))[0].docstring() >>> print(doc) f(a, b=1) Document for function f. Notice that useful extra information is added to the actual docstring, e.g. function signatures are prepended to their docstrings. If you need the actual docstring, use ``raw=True`` instead. >>> print(script.infer(1, len('def f'))[0].docstring(raw=True)) Document for function f. :param fast: Don't follow imports that are only one level deep like ``import foo``, but follow ``from foo import bar``. This makes sense for speed reasons. Completing `import a` is slow if you use the ``foo.docstring(fast=False)`` on every object, because it parses all libraries starting with ``a``. z )rTrSr _get_docstring_get_docstring_signature)rVrawfastdocsignature_texts r docstringzBaseName.docstring s[> djj* -$!!# J668 c!F*S0 0!C' 'rc6|jjSr2)rS py__doc__rZs rrzBaseName._get_docstring6szz##%%rcRdjd|jdDS)N c3<K|]}|jywr2) to_string)rM signatures rrPz4BaseName._get_docstring_signature..:s!     ! ruT) for_docstring)join_get_signaturesrZs rrz!BaseName._get_docstring_signature9s.yy !111E   rc|j}|jj}|dk(r |dz|jjzS|dvs|'|dk(rd}|dz|jj zS|j dxs|}|j d }tjd d|}tjd d|j}|S) aZ A description of the :class:`.Name` object, which is heavily used in testing. e.g. for ``isinstance`` it returns ``def isinstance``. Example: >>> from jedi import Script >>> source = ''' ... def f(): ... pass ... ... class C: ... pass ... ... variable = f if random.choice([0,1]) else C''' >>> script = Script(source) # line is maximum by default >>> defs = script.infer(column=3) >>> defs = sorted(defs, key=lambda d: d.line) >>> print(defs) # doctest: +NORMALIZE_WHITESPACE [, ] >>> str(defs[0].description) 'def f' >>> str(defs[1].description) 'class C' param )rrrainstancerdefT)include_setitemF)include_prefixz #[^\n]+\nz\s+) rjrSrhrreriget_coderesubstrip)rVtyprhrotxts r descriptionzBaseName.description?s:iiJJ(( '>9tzz3355 5 = =ARj 9tzz99;; ;--d-CPy !!!7ff\3,ffVS#&,,. rc|jjsy|jjd}|yt|} |j|d|d<dj |S#t $rYwxYw)a Dot-separated path of this object. It is in the form of ``[.[...]][.]``. It is useful when you want to look up Python manual of the object at hand. Example: >>> from jedi import Script >>> source = ''' ... import os ... os.path.join''' >>> script = Script(source, path='example.py') >>> print(script.infer(3, len('os.path.join'))[0].full_name) os.path.join Notice that it returns ``'os.path.join'`` instead of (for example) ``'posixpath.join'``. This is not correct, since the modules name would be `````. However most users find the latter more practical. NT)include_module_namesrrJ)rS is_value_nameget_qualified_nameslist_mappingKeyErrorr)rVr"s r full_namezBaseName.full_nameps{0zz'' ..D.I =U  }}U1X.E!Hxx   sA)) A54A5c|jjsy|jjjS)zM Returns True if the current name is defined in a stub file. F)rSrrYr^rZs rr^zBaseName.is_stubs0zz''zz**,4466rc|jj}|y|jxr|jjdk(S)z Checks if a name is defined as ``self.foo = 3``. In case of self, this function would return False, for foo it would return True. Ftrailer)rSrhrkparentrj)rVrhs ris_side_effectzBaseName.is_side_effectsA JJ((  &&(OY-=-=-B-Bi-OOrz goto on name)follow_importsfollow_builtin_imports only_stubs prefer_stubsc|jjsgS|jj}|r t||}t |||}|Dcgc])}||jk(r|nt |j |+c}Scc}w)ag Like :meth:`.Script.goto` (also supports the same params), but does it for the current name. This is typically useful if you are using something like :meth:`.Script.get_names()`. :param follow_imports: The goto call will follow imports. :param follow_builtin_imports: If follow_imports is True will try to look up names in builtins (i.e. compiled or extension modules). :param only_stubs: Only return stubs for this goto call. :param prefer_stubs: Prefer stubs to Python objects for this goto call. :rtype: list of :class:`Name` rr)rSrgotorrr)rR)rVrrrrr"r/s rrz BaseName.gotos zz''I ! )%1GHE !%   TZZT$2G2G-KK   s.Bz infer on namercn|r|rJ|jjsgSt|jgd}tt j d|D||}|Dcgc]}|j }}|Dcgc])}||jk(r|nt|j|+c}Scc}wcc}w)a Like :meth:`.Script.infer`, it can be useful to understand which type the current name has. Return the actual definitions. I strongly recommend not using it for your completions, because it might slow down |jedi|. If you want to read only a few objects (<=20), it might be useful, especially to get the original docstrings. The basic problem of this function is that it follows all results. This means with 1000 completions (e.g. numpy), it's just very, very slow. :param only_stubs: Only return stubs for this goto call. :param prefer_stubs: Prefer stubs to Python objects for this type inference call. :rtype: list of :class:`Name` Trc3<K|]}|jywr2)rl)rMr/s rrPz!BaseName.infer..s8Qqwwy8rur) rSrrrr from_setsr.r)rR)rVrrr"r(r3resulting_namesr/s rrlzBaseName.infers$<00zz''I tzzl>   8%8 8!%  ,22a16622(*TZZT$2G2G-KK* *3*s #B-<.B2c|jjsy|jdvrv|jj`|jjj }t |ddd}|j j|j}n|jj}|y|j|j}|jt|j|jS)zT Returns the parent scope of this identifier. :rtype: Name N)rrrfuncdefclassdef file_input) rSrrjrhrirr[ create_valuer%parent_contextr.r)rR)rVcls_or_func_noderr,s rrzBaseName.parents zz'' 996 64::;O;O;[ $zz33BBD $%5y*l[F..0==fEPPRGjj//G ?ll",,Gll"D))7<<88rc d|jjd|jrdndd|jxs |jd|jd S)N) __class____name__rr.rrZs r__repr__zBaseName.__repr__ sC NN # #~~G2 - NN 'dii '      rc|jjsy|jjj}|y|jjddz }t ||z d}dj ||||zdzS)aI Returns the line of code where this object was defined. :param before: Add n lines before the current line to the output. :param after: Add n lines after the current line to the output. :return str: Returns the line(s) of code or an empty string if it's a builtin. rrr)rSrrY code_linesrmaxr)rVbeforeafterlinesindex start_indexs r get_line_codezBaseName.get_line_codes|zz'' ++-88 = $$Q'!+%&.!, wwu[):;< %O1L1L1NO#OOOOs(,Ccp|jDcgc]}t|j|c}Scc}w)z Returns all potential signatures for a function or a class. Multiple signatures are typical if you use Python stubs with ``@overload``. :rtype: list of :class:`BaseSignature` )r BaseSignaturerR)rVrs rrzBaseName.get_signatures<s:))+  $// 3   s3cdt|jjjS)z Uses type inference to "execute" this identifier and returns the executed objects. :rtype: list of :class:`Name` )r4rSrlexecute_with_valuesrZs rexecutezBaseName.executeHs%&djj&6&6&8&L&L&NOOrcR|jjjS)a* Returns type hints like ``Iterable[int]`` or ``Union[int, str]``. This method might be quite slow, especially for functions. The problem is finding executions for those functions to return something like ``Callable[[int, str], str]``. :rtype: str )rSrl get_type_hintrZs rrzBaseName.get_type_hintQs zz!//11rNFTr)F))r __module__ __qualname____doc__rdictitems_tuple_mappingrWr r[rrrrcr.rjrrryr}rrrrrrrrr^rrincrease_indent_cmrrlrrrrrrrrrr6r6<s !% H$&?B egN>--  Xd^  ,,D#D#L 7 7# $"&)(V& ..`$$L7PUn-%*5E . :Uo."'e!*/!*F9B =,P"  P 2rr6ceZdZdZ d fd ZdZedZedZdfd Z fdZ fdZ fd Z efd Z d Zd ZxZS) Completionz ``Completion`` objects are returned from :meth:`.Script.complete`. They provide additional information about a completion. clt|||||_||_||_||_g|_yr2)superrW_like_name_length_stack _is_fuzzy _cached_name_same_name_completions)rVr*r.stacklike_name_lengthis_fuzzy cached_namers rrWzCompletion.__init__cs: $/!1 !'')#rcd}tjr|jdk(rd}|jj }|r||j d}||zS)Nrr()radd_bracket_after_functionrjrSrer)rV like_nameappendr.s r _completezCompletion._completepsS  . .II+Fzz))+ ../0Df}rc>|jry|jdS)a! Only works with non-fuzzy completions. Returns None if fuzzy completions are used. Return the rest of the word, e.g. completing ``isinstance``:: isinstan# <-- Cursor is here would return the string 'ce'. It also adds additional stuff, depending on your ``settings.py``. Assuming the following function definition:: def foo(param=0): pass completing ``foo(par`` would give a ``Completion`` which ``complete`` would be ``am=``. NT)rrrZs rcompletezCompletion.complete{s* >>~~d##rc$|jdS)aB Similar to :attr:`.name`, but like :attr:`.name` returns also the symbols, for example assuming the following function definition:: def foo(param=0): pass completing ``foo(`` would give a ``Completion`` which ``name_with_symbols`` would be "param=". F)rrZs rname_with_symbolszCompletion.name_with_symbolss~~e$$rcH|jdk\rd}t| ||S)z> Documented under :meth:`BaseName.docstring`. F)rr)rrr)rVrrrs rrzCompletion.docstrings/  ! !Q &Dw St 44rcj.)r)rr get_docstringrSrerrrVrs`rrzCompletion._get_docstringsN    (#11!! **,)  w%''rcj.rr)rrget_docstring_signaturerSrerrrs`rrz#Completion._get_docstring_signaturesN    (#;;!! **,)  w/11rcNt|t| t| fSr2)rrjrrrs rrzCompletion._get_caches* GL G , . G " $  rcj.rr)rrget_typerSrerrjrs`rrjzCompletion.typesL    (#,,!! **,)  w|rc|jS)ao Returns the length of the prefix being completed. For example, completing ``isinstance``:: isinstan# <-- Cursor is here would return 8, because len('isinstan') == 8. Assuming the following function definition:: def foo(param=0): pass completing ``foo(par`` would return 3. )rrZs rget_completion_prefix_lengthz'Completion.get_completion_prefix_lengths %%%rcjdt|jd|jjdS)Nrz: r)rjrrSrerZs rrzCompletion.__repr__s$!$Z00$**2L2L2NOOrr2r)rrrrrWrrrr rrrrrjrr __classcell__rs@rrr^sr (, ) $$0 % % 5(2   &$PrrcJeZdZdZfdZedZdZdZdZ dZ xZ S)r)z{ *Name* objects are returned from many different APIs including :meth:`.Script.goto` or :meth:`.Script.infer`. c&t|||yr2)rrW)rVr*rors rrWz Name.__init__s *5rcxjj}ttfd|DdS)zg List sub-definitions (e.g., methods in class). :rtype: list of :class:`Name` c3JK|]}tj|ywr2)r0rR)rMdrVs rrPz%Name.defined_names..sHa- 5 5q9Hs #c6|jjxsdSrr{rs rrz$Name.defined_names..s!''++5vrr)rSrlr!r)rVdefss` rr0zName.defined_namess5zz! H4H H5  rcx|jjy|jjjS)z Returns True, if defined as a name in a statement, function or class. Returns False, if it's a reference to such a definition. T)rSrhrkrZs rrkzName.is_definitions0 ::   '::''557 7rc|jj|jjk(xrO|j|jk(xr4|j|jk(xr|j|jk(Sr2)rSrrcr.rRrVothers r__eq__z Name.__eq__ spzz##u{{'<'<<@  E$5$55@ UZZ'@%%)?)?? @rc&|j| Sr2)r+r)s r__ne__z Name.__ne__s;;u%%%rct|jj|j|j|j fSr2)hashrSrrcr.rRrZs r__hash__z Name.__hash__s0TZZ))4+;+;TYYH]H]^__r) rrrrrWr r0rkr+r-r0rrs@rr)r)s76    8@ &`rr)c8eZdZdZfdZedZdZxZS)rzU These signatures are returned by :meth:`BaseName.get_signatures` calls. cHt|||j||_yr2)rrWr. _signature)rVr*rrs rrWzBaseSignature.__init__s )..9#rc|jjdDcgc]}t|j|c}Scc}w)z Returns definitions for all parameters that a signature defines. This includes stuff like ``*args`` and ``**kwargs``. :rtype: list of :class:`.ParamName` T resolve_stars)r3get_param_names ParamNamerR)rVr/s rparamszBaseSignature.params!sG88t8LN$//3N NNs?c6|jjS)z Returns a text representation of the signature. This could for example look like ``foo(bar, baz: int, **kwargs)``. :rtype: str )r3rrZs rrzBaseSignature.to_string,s((**r) rrrrrWrr9rrrs@rrrs($NN+rrcHeZdZdZfdZedZedZdZxZ S) Signaturez\ A full signature object is the return value of :meth:`.Script.get_signatures`. cBt|||||_||_yr2)rrW _call_detailsr3)rVr*r call_detailsrs rrWzSignature.__init__;s! )4)#rcl|jj|jjdS)z Returns the param index of the current cursor position. Returns None if the index cannot be found in the curent call. :rtype: int Tr5)r>calculate_indexr3r7rZs rrzSignature.index@s2!!11 OO + +$ + ?  rcB|jjjS)z Returns a line/column tuple of the bracket that is responsible for the last function call. The first line is 1 and the first column 0. :rtype: int, int )r> bracket_leafrrZs r bracket_startzSignature.bracket_startLs!!..888rcdt|jd|jd|jj dS)Nrz: index=rr)rjrrr3rrZs rrzSignature.__repr__Vs0 J   JJ OO % % '  r) rrrrrWrrrDrrrs@rr<r<6s:$     99 rr<c.eZdZdZdZdZedZy)r8cHt|jjS)zu Returns default values like the ``1`` of ``def foo(x=1):``. :rtype: list of :class:`.Name` )r4rS infer_defaultrZs rrHzParamName.infer_default_s &djj&>&>&@AArc Pt|jjdddi|S)z :param execute_annotation: Default True; If False, values are not executed and classes are returned instead of instances. :rtype: list of :class:`.Name` ignore_starsTr)r4rSinfer_annotation)rVkwargss rrKzParamName.infer_annotationgs* &&Adjj&A&A&^t&^W]&^__rc6|jjS)zz Returns a simple representation of a param, like ``f: Callable[..., Any]``. :rtype: str )rSrrZs rrzParamName.to_stringoszz##%%rc6|jjS)z Returns an enum instance of :mod:`inspect`'s ``Parameter`` enum. :rtype: :py:attr:`inspect.Parameter.kind` )rSget_kindrZs rkindzParamName.kindxszz""$$rN)rrrrHrKrrrPrrrr8r8^s'B`&%%rr8)+rrpathlibrtypingr parso.treerjedirrjedi.inference.utilsr jedi.cacher jedi.inference.compiled.mixedr jedi.inference.namesr r !jedi.inference.gradual.stub_valuer !jedi.inference.gradual.conversionrrjedi.inference.base_valuerrjedi.api.keywordsrjedi.apirjedi.api.helpersrr#r0r4r6rr)rr<r8rrrr_s &&%3:=K<)%2> O =_2_2DKPKP\)`8)`X+D+<% % P!%!%r