mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Don't follow builtin imports anymore by default when follow_imports is on (goto)
This commit is contained in:
@@ -7,6 +7,8 @@ Changelog
|
|||||||
+++++++++++++++++++
|
+++++++++++++++++++
|
||||||
|
|
||||||
- Added ``include_builtins`` as a parameter to usages.
|
- Added ``include_builtins`` as a parameter to usages.
|
||||||
|
- ``goto_assignments`` has a new ``follow_builtin_imports`` parameter that
|
||||||
|
changes the previous behavior slightly.
|
||||||
|
|
||||||
0.12.1 (2018-06-30)
|
0.12.1 (2018-06-30)
|
||||||
+++++++++++++++++++
|
+++++++++++++++++++
|
||||||
|
|||||||
@@ -204,20 +204,33 @@ class Script(object):
|
|||||||
# the API.
|
# the API.
|
||||||
return helpers.sorted_definitions(set(defs))
|
return helpers.sorted_definitions(set(defs))
|
||||||
|
|
||||||
def goto_assignments(self, follow_imports=False):
|
def goto_assignments(self, follow_imports=False, follow_builtin_imports=False):
|
||||||
"""
|
"""
|
||||||
Return the first definition found, while optionally following imports.
|
Return the first definition found, while optionally following imports.
|
||||||
Multiple objects may be returned, because Python itself is a
|
Multiple objects may be returned, because Python itself is a
|
||||||
dynamic language, which means depending on an option you can have two
|
dynamic language, which means depending on an option you can have two
|
||||||
different versions of a function.
|
different versions of a function.
|
||||||
|
|
||||||
|
:param follow_imports: The goto call will follow imports.
|
||||||
|
:param follow_builtin_imports: If follow_imports is True will decide if
|
||||||
|
it follow builtin imports.
|
||||||
:rtype: list of :class:`classes.Definition`
|
:rtype: list of :class:`classes.Definition`
|
||||||
"""
|
"""
|
||||||
def filter_follow_imports(names, check):
|
def filter_follow_imports(names, check):
|
||||||
for name in names:
|
for name in names:
|
||||||
if check(name):
|
if check(name):
|
||||||
for result in filter_follow_imports(name.goto(), check):
|
new_names = list(filter_follow_imports(name.goto(), check))
|
||||||
yield result
|
found_builtin = False
|
||||||
|
if follow_builtin_imports:
|
||||||
|
for new_name in new_names:
|
||||||
|
if new_name.start_pos is None:
|
||||||
|
found_builtin = True
|
||||||
|
|
||||||
|
if found_builtin and not isinstance(name, imports.SubModuleName):
|
||||||
|
yield name
|
||||||
|
else:
|
||||||
|
for new_name in new_names:
|
||||||
|
yield new_name
|
||||||
else:
|
else:
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
|
|||||||
@@ -285,3 +285,11 @@ def test_backslash_continuation_and_bracket(Script):
|
|||||||
column = lines[-1].index('(')
|
column = lines[-1].index('(')
|
||||||
def_, = Script(code, line=len(lines), column=column).goto_definitions()
|
def_, = Script(code, line=len(lines), column=column).goto_definitions()
|
||||||
assert def_.name == 'int'
|
assert def_.name == 'int'
|
||||||
|
|
||||||
|
|
||||||
|
def test_goto_follow_builtin_imports(Script):
|
||||||
|
s = Script('import sys; sys')
|
||||||
|
d, = s.goto_assignments(follow_imports=True)
|
||||||
|
assert d.in_builtin_module() is True
|
||||||
|
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
|
||||||
|
assert d.in_builtin_module() is False
|
||||||
|
|||||||
Reference in New Issue
Block a user