本文整理汇总了Python中jedi.Script.goto_definitions方法的典型用法代码示例。如果您正苦于以下问题:Python Script.goto_definitions方法的具体用法?Python Script.goto_definitions怎么用?Python Script.goto_definitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jedi.Script
的用法示例。
在下文中一共展示了Script.goto_definitions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_dynamic_mods
# 需要导入模块: from jedi import Script [as 别名]
# 或者: from jedi.Script import goto_definitions [as 别名]
def test_add_dynamic_mods(self):
fname = '__main__.py'
api.settings.additional_dynamic_modules = [fname]
# Fictional module that defines a function.
src1 = "def r(a): return a"
# Other fictional modules in another place in the fs.
src2 = 'from .. import setup; setup.r(1)'
script = Script(src1, path='../setup.py')
imports.load_module(script._evaluator, os.path.abspath(fname), src2)
result = script.goto_definitions()
assert len(result) == 1
assert result[0].description == 'class int'
示例2: make_definitions
# 需要导入模块: from jedi import Script [as 别名]
# 或者: from jedi.Script import goto_definitions [as 别名]
def make_definitions():
"""
Return a list of definitions for parametrized tests.
:rtype: [jedi.api_classes.BaseDefinition]
"""
source = dedent(
"""
import sys
class C:
pass
x = C()
def f():
pass
def g():
yield
h = lambda: None
"""
)
definitions = []
definitions += defined_names(source)
source += dedent(
"""
variable = sys or C or x or f or g or g() or h"""
)
lines = source.splitlines()
script = Script(source, len(lines), len("variable"), None)
definitions += script.goto_definitions()
script2 = Script(source, 4, len("class C"), None)
definitions += script2.usages()
source_param = "def f(a): return a"
script_param = Script(source_param, 1, len(source_param), None)
definitions += script_param.goto_assignments()
return definitions
示例3: finddocstring
# 需要导入模块: from jedi import Script [as 别名]
# 或者: from jedi.Script import goto_definitions [as 别名]
def finddocstring(self):
''' find the docstring at current cursor location
'''
import StringIO
from jedi import Script
i=editor.get_selection()
t=editor.get_text()
(line,txt)=[(line,n) for (line,n) in enumerate(StringIO.StringIO(editor.get_text()[:i[1]]))][-1]
script = Script(t, line+1, len(txt))
dfn = script.goto_definitions()
if dfn:
doc=dfn[0].doc
import ui
v=ui.TextView()
v.width=100
v.height=50
v.text=doc
editor._set_toolbar(v)