uBFjxs~dZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z dd l mZdd lmZmZdd lmZdd lmZmZdd lmZmZddlmZddlmZddlmZdZ dZ!dZ"GddZ#Gdde#Z$Gdde#Z%Gdde%Z&Gdde&Z'Gdde%Z(dS) 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)settings)debug)unite)memoize_method) MixedName) ImportName SubModuleName)StubModuleValue) convert_namesconvert_values)ValueSet HasNoContext) KeywordName)completion_cache)filter_follow_importsc&t|dS)Nc|jpdSNrr) start_posss >C:\PYTHON\_runtimes\venv\Lib\site-packages\jedi/api/classes.pyz*_sort_names_by_start_pos..#s q{'z!defined_names..2s . . .dT . . .rc0g|]}t|Sr%)Name)r&ninference_states rr(z!defined_names..3s# N N ND! $ $ N N Nr) as_contextrnext get_filtersvaluesr")r,valuecontextfilterr!s` r defined_namesr4&s""$$   '%%'' ( (F . .fmmoo . . .E N N N N.Fu.M.M N N NNs  ''cd|DS)NcBg|]}t|j|jSr%)r*r,r'r&cs rr(z*_values_to_definitions..7s' < < <D"AF + + < < zBaseName.MsMv15..2rzargparse._ActionsContainerzargparse.ArgumentParsercb||_||_ t|jt|_dSN)_inference_state_name isinstancer is_keyword)selfr,r's r__init__zBaseName.__init__Qs/ /  %TZ==rc4|jSrV)rXget_root_contextr[s r_get_module_contextzBaseName._get_module_contextYs z**,,,rreturnc|}|s|s(|}|SdS)zU Shows the file path of a module. e.g. ``/usr/lib/python3.14/os.py`` N)r`is_stub is_compiled py__file__)r[modulepaths r module_pathzBaseName.module_path`sc ))++ >>   6#5#5#7#7 $(#;#;#=#=#H#H#J#JDKtrc4|jS)z Name of variable/function/class/module. For example, for ``x = None`` it returns ``'x'``. :rtype: str or None )rXget_public_namer_s rr'z BaseName.namensz))+++rc(|jj}d}|7|}|!|jdkr|rd}t |jt s|r$|jD] }|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``. FN import_fromT) rX tree_nameget_definitiontype is_definitionrYr inferapi_type)r[rmresolve definitionr1s rroz BaseName.typeysrJ(   "1133J%*/]*J*J++--+K dj- 0 0 &G &))++ & &~%%%z""rcN|S)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__r_s r module_namezBaseName.module_names"''))44666rc|}t|trt d|jDS|S)z< Returns True, if this is a builtin module. c3>K|]}|VdSrV)rd)r&rSs rrTz-BaseName.in_builtin_module..s*II1q}}IIIIIIr)r` get_valuerYr anynon_stub_value_setrd)r[r1s rin_builtin_modulezBaseName.in_builtin_modulesf((**4466 e_ - - JII0HIIIII I  """rc2|jj}|dS|dS)z7The line where the definition occurs (starting with 1).NrrXrr[rs rlinez BaseName.line#J(  4|rc2|jj}|dS|dS)z9The column where the definition occurs (starting with 0).Nrrs rcolumnzBaseName.columnrrc|jjdS|jj}| |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)rXrmrnr)r[rts rget_definition_start_positionz&BaseName.get_definition_start_positionsD :  '4Z)88::  :' '##rc|jjdS|jj}||jjjS|jdvr?|}|jdkr|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)rXrmrnend_posro get_last_leafget_previous_leaf)r[rt last_leafs rget_definition_end_positionz$BaseName.get_definition_end_positions :  '4Z)88::  :'/ / 9- - -"0022I~** 2244<<$ $!!rFTct|jtr|rdS|}|r|S|}|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 )rYrXr _get_docstring_get_docstring_signature)r[rawfastdocsignature_texts r docstringzBaseName.docstring s}> dj* - - $ 2!!##  J6688  (c (!F*S0 0!C' 'rc4|jSrV)rX py__doc__r_s rrzBaseName._get_docstring4sz##%%%rchdd|dDS)N c3>K|]}|VdSrV) to_string)r& signatures rrTz4BaseName._get_docstring_signature..8sB      ! !      rT) for_docstring)join_get_signaturesr_s rrz!BaseName._get_docstring_signature7sEyy  !111EE      rc|j}|jj}|dkr|dz|jzS|dvs|'|dkrd}|dz|jzS|dp|}|d }tjd d|}tjd d| }|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 )rrrfinstanceNrdefT)include_setitemF)include_prefixz #[^\n]+\nz\s+) rorXrmrrjrnget_coderesubstrip)r[typrmrttxts r descriptionzBaseName.description=s:iJ( '>>9tz33555 5 = = =ARj  9tz99;;; ;--d-CCPy !!!77f\3,,fVS#&&,,.. rc|jjsdS|jd}|dSt|} |j|d|d<n#t $rYnwxYwd|S)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_namesrrO)rX is_value_nameget_qualified_nameslist_mappingKeyErrorr)r[r!s r full_namezBaseName.full_namens0z' 4 ..D.II =4U  }U1X.E!HH    D xxsA A"!A"ct|jjsdS|jS)zM Returns True if the current name is defined in a stub file. F)rXrr^rcr_s rrczBaseName.is_stubs6z' 5z**,,44666rcj|jj}|dS|o|jjdkS)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. NFtrailer)rXrmrpparentro)r[rms ris_side_effectzBaseName.is_side_effects; J(  5&&((OY-=-Bi-OOrz goto on name)follow_importsfollow_builtin_imports only_stubs prefer_stubscjjsgSj}|rt||}t |||}fd|DS)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` rrcTg|]$}|jkrntj|%Sr%rXr*rWr&r+r[s rr(z!BaseName.goto..sD   TZT$2G-K-K   r)rXrgotorr )r[rrrrr!s` rrz BaseName.gotos z' I !!  I)%1GHHE !%            rz infer on namerc|r|rJjjsgStjgd}tt jd|D||}d|D}fd|DS)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|]}|VdSrV)rq)r&r+s rrTz!BaseName.infer..s*88Qqwwyy888888rrcg|] }|j Sr%)r'r7s rr(z"BaseName.infer..s222a16222rcTg|]$}|jkrntj|%Sr%rrs rr(z"BaseName.infer..sD***TZT$2G-K-K***r)rXrr rr from_sets)r[rrr!r0resulting_namess` rrqzBaseName.infers$0<000z' I tzl>>>  88%888 8 8!%    326222****(*** *rc|jjsdS|jdvr{|jjo|jj}|ddd}||}n |jj }|dS|j |j }|j t|j |j S)zT Returns the parent scope of this identifier. :rtype: Name N)rrrfuncdefclassdef file_input) rXrrormrnsearch_ancestorr` create_valuer-parent_contextr'r*rW)r[cls_or_func_noderr2s rrzBaseName.parents z' 4 96 6 64:;O;[ $z3BBDD %55i\ZZF..00==fEEPPRRGGj/G ?4l",Gl"D)7<888rc hd|jjd|jrdndd|jp|jd|jd S)N) __class____name__rr'rr_s r__repr__zBaseName.__repr__ sN N # # #~ -GG2 - - N 'di ' '       rrc|jjsdS|jj}|dS|jjddz }t ||z d}d||||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. rNrr)rXrr^ code_linesrmaxr)r[beforeafterlinesindex start_indexs r get_line_codezBaseName.get_line_codesz' 2 ++--8 =2 $Q'!+%&.!,, wwu[)::;<<.8s9OOO1L1L1N1NOO#OOOOr)rXrrrcrYr infer_compiled_valuerr )r[rr!s rrzBaseName._get_signatures)s : * , ,I  TZ0K?? ?I dj) , , F:2244CCEE Etzl>>>OOOOOOrcDfdDS)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` c:g|]}tj|Sr%) BaseSignaturerW)r&rr[s rr(z+BaseName.get_signatures..As6    $/ 3 3   r)rr_s`rrzBaseName.get_signatures:s:    ))++    rcrt|jS)z Uses type inference to "execute" this identifier and returns the executed objects. :rtype: list of :class:`Name` )r9rXrqexecute_with_valuesr_s rexecutezBaseName.executeFs,&dj&6&6&8&8&L&L&N&NOOOrcX|jS)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 )rXrq get_type_hintr_s rrzBaseName.get_type_hintOs$z!!//111rNFTr)F))r __module__ __qualname____doc__rdictitems_tuple_mappingr\rr`rrrrhr'rorwr}rrrrrrrrrrcrrincrease_indent_cmrrqrrrrrrrr%rrr;r;:s !%  HT$&?B eggN>>>--^-  Xd^   X ,,X,D#D#XD#L 7 7X 7###XX $ $ $"""&)()()()(V&&&   ..X.`$$X$L777PPPUn--%*5E    .- :Uo.."'e!*!*!*!*/.!*F999B   ====,PPPP"    PPP 2 2 2 2 2rr;ceZdZdZ dfd ZdZedZedZdfd Z fd Z fd Z fd Z efd Z dZdZxZS) Completionz ``Completion`` objects are returned from :meth:`.Script.complete`. They provide additional information about a completion. Nct||||_||_||_||_g|_dSrV)superr\_like_name_length_stack _is_fuzzy _cached_name_same_name_completions)r[r,r'stacklike_name_lengthis_fuzzy cached_namers rr\zCompletion.__init__asK $///!1 !'')###rcd}tjr |jdkrd}|j}|r||jd}||zS)Nrr()radd_bracket_after_functionrorXrjr)r[ like_nameappendr's r _completezCompletion._completens\  . I++Fz))++  1.//0Df}rc>|jrdS|dS)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)rrr_s rcompletezCompletion.completeys%* > 4~~d###rc,|dS)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)rr_s rname_with_symbolszCompletion.name_with_symbolss~~e$$$rFTcd|jdkrd}t||S)z> Documented under :meth:`BaseName.docstring`. F)rr)rrr)r[rrrs rrzCompletion.docstrings7  !Q & &Dww  St 444rcj5tjjjfdSt S)Nc,SrV _get_cacher_srrz+Completion._get_docstring..))r)rr get_docstringrXrjrrr[rs`rrzCompletion._get_docstrings]   (#1! **,,))))  ww%%'''rcj5tjjjfdSt S)Nc,SrVrr_srrz5Completion._get_docstring_signature..rr)rrget_docstring_signaturerXrjrrrs`rrz#Completion._get_docstring_signatures]   (#;! **,,))))  ww//111rctjttfSrV)rrorrrs rrzCompletion._get_caches< GGL GG , , . . GG " " $ $  rcj5tjjjfdSt jS)z9 Documented under :meth:`BaseName.type`. Nc,SrVrr_srrz!Completion.type..rr)rrget_typerXrjrrors`rrozCompletion.typesU   (#,! **,,))))  ww|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. )rr_s rget_completion_prefix_lengthz'Completion.get_completion_prefix_lengths %%rcfdt|jd|jdS)Nrz: r)rorrXrjr_s rrzCompletion.__repr__s2!$ZZ000$*2L2L2N2N2N2NOOrrVr)rrrrr\rrrrrrrrror'r __classcell__rs@rrr\sD (, ) ) ) ) ) )   $$X$0 % %X % 5 5 5 5 5 5(((((22222         X &&&$PPPPPPPrrcPeZdZdZfdZedZdZdZdZ dZ xZ S)r*z{ *Name* objects are returned from many different APIs including :meth:`.Script.goto` or :meth:`.Script.infer`. cLt||dSrV)rr\)r[r,rtrs rr\z Name.__init__s# *55555rcj}ttfd|DdS)zg List sub-definitions (e.g., methods in class). :rtype: list of :class:`Name` c3BK|]}tj|VdSrV)r4rW)r&dr[s rrTz%Name.defined_names..s0HHa- 5q99HHHHHHrc|jjpdSrrrs rrz$Name.defined_names..s!'+5vrr)rXrqr r)r[defss` rr4zName.defined_namessUz!! HHHH4HHH H H55    rcZ|jjdS|jjS)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. NT)rXrmrpr_s rrpzName.is_definitions+ :  '4:'5577 7rc|jj|jjko/|j|jko|j|jko|j|jkSrV)rXrrhr'rWr[others r__eq__z Name.__eq__ sVz#u{'<<@ E$55@ UZ'@%)?? @rc.|| SrV)r6r4s r__ne__z Name.__ne__s;;u%%%%rcZt|jj|j|j|jfSrV)hashrXrrhr'rWr_s r__hash__z Name.__hash__s&TZ)4+;TYH]^___r) rrrrr\rr4rpr6r8r;r)r*s@rr*r*s66666   ^  888@@@ &&&```````rr*c>eZdZdZfdZedZdZxZS)rzU These signatures are returned by :meth:`BaseName.get_signatures` calls. cdt||j||_dSrV)rr\r' _signature)r[r,rrs rr\zBaseSignature.__init__s* ).999#rcRfdjdDS)z Returns definitions for all parameters that a signature defines. This includes stuff like ``*args`` and ``**kwargs``. :rtype: list of :class:`.ParamName` c:g|]}tj|Sr%) ParamNamerWrs rr(z(BaseSignature.params..'s<NNN$/33NNNrT resolve_stars)r>get_param_namesr_s`rparamszBaseSignature.paramssINNNN88t8LLNNN Nrc4|jS)z Returns a text representation of the signature. This could for example look like ``foo(bar, baz: int, **kwargs)``. :rtype: str )r>rr_s rrzBaseSignature.to_string*s((***r) rrrrr\rrErr)r*s@rrrso$$$$$NNXN+++++++rrcTeZdZdZfdZedZedZdZxZ S) Signaturez\ A full signature object is the return value of :meth:`.Script.get_signatures`. cht||||_||_dSrV)rr\ _call_detailsr>)r[r,r call_detailsrs rr\zSignature.__init__9s0 )444)#rch|j|jdS)z Returns the param index of the current cursor position. Returns None if the index cannot be found in the curent call. :rtype: int TrB)rJcalculate_indexr>rDr_s rrzSignature.index>s5!11 O + +$ + ? ?   rc$|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 )rJ bracket_leafrr_s r bracket_startzSignature.bracket_startJs!.88rcvdt|jd|jd|jdS)Nrz: index=rr)rorrr>rr_s rrzSignature.__repr__Ts@ JJ    JJJ O % % ' ' ' '  r) rrrrr\rrrPrr)r*s@rrHrH4s$$$$$    X  99X9       rrHc6eZdZdZdZdZedZdS)rAcNt|jS)zu Returns default values like the ``1`` of ``def foo(x=1):``. :rtype: list of :class:`.Name` )r9rX infer_defaultr_s rrTzParamName.infer_default]s &dj&>&>&@&@AAArc Dt|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%)r9rXinfer_annotation)r[kwargss rrWzParamName.infer_annotationes. &&Adj&A&^&^t&^W]&^&^___rc4|jS)zz Returns a simple representation of a param, like ``f: Callable[..., Any]``. :rtype: str )rXrr_s rrzParamName.to_stringmsz##%%%rc4|jS)z Returns an enum instance of :mod:`inspect`'s ``Parameter`` enum. :rtype: :py:attr:`inspect.Parameter.kind` )rXget_kindr_s rkindzParamName.kindvsz""$$$rN)rrrrTrWrrr\r%rrrArA\sbBBB```&&&%%X%%%rrA))rrpathlibrtypingrjedirrjedi.inference.utilsr jedi.cacherjedi.inference.compiled.mixedr jedi.inference.namesr r !jedi.inference.gradual.stub_valuer !jedi.inference.gradual.conversionr rjedi.inference.base_valuerrjedi.api.keywordsrjedi.apirjedi.api.helpersrr"r4r9r;rr*rrHrAr%rrrjs &&&&&&%%%%%%333333::::::::======KKKKKKKK<<<<<<<<))))))%%%%%%222222>>> O O O ===_2_2_2_2_2_2_2_2DKPKPKPKPKPKPKPKP\)`)`)`)`)`8)`)`)`X+++++D+++<% % % % % % % % P!%!%!%!%!%!%!%!%!%!%r