Don't follow builtin imports anymore by default when follow_imports is on (goto)

This commit is contained in:
Dave Halter
2018-07-03 23:59:30 +02:00
parent 6cdc1bcd8a
commit 2500112f6c
3 changed files with 26 additions and 3 deletions

View File

@@ -204,20 +204,33 @@ class Script(object):
# the API.
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.
Multiple objects may be returned, because Python itself is a
dynamic language, which means depending on an option you can have two
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`
"""
def filter_follow_imports(names, check):
for name in names:
if check(name):
for result in filter_follow_imports(name.goto(), check):
yield result
new_names = list(filter_follow_imports(name.goto(), check))
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:
yield name