mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 09:48:36 +08:00
Fix a failure when run with Python 3
This commit is contained in:
+9
-3
@@ -272,7 +272,7 @@ class Script(object):
|
|||||||
|
|
||||||
d = set([api_classes.Definition(s) for s in scopes
|
d = set([api_classes.Definition(s) for s in scopes
|
||||||
if not isinstance(s, imports.ImportPath._GlobalNamespace)])
|
if not isinstance(s, imports.ImportPath._GlobalNamespace)])
|
||||||
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
@api_classes._clear_caches_after_call
|
@api_classes._clear_caches_after_call
|
||||||
def goto(self):
|
def goto(self):
|
||||||
@@ -285,7 +285,7 @@ class Script(object):
|
|||||||
:rtype: list of :class:`api_classes.Definition`
|
:rtype: list of :class:`api_classes.Definition`
|
||||||
"""
|
"""
|
||||||
d = [api_classes.Definition(d) for d in set(self._goto()[0])]
|
d = [api_classes.Definition(d) for d in set(self._goto()[0])]
|
||||||
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
def _goto(self, add_import_name=False):
|
def _goto(self, add_import_name=False):
|
||||||
"""
|
"""
|
||||||
@@ -371,7 +371,7 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
names.append(api_classes.RelatedName(d.names[-1], d))
|
names.append(api_classes.RelatedName(d.names[-1], d))
|
||||||
|
|
||||||
return sorted(set(names), key=lambda x: (x.module_path, x.start_pos))
|
return self._sorted_defs(set(names))
|
||||||
|
|
||||||
def get_in_function_call(self):
|
def get_in_function_call(self):
|
||||||
"""
|
"""
|
||||||
@@ -492,6 +492,12 @@ class Script(object):
|
|||||||
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path, flags=re.S)
|
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path, flags=re.S)
|
||||||
return match.groups()
|
return match.groups()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _sorted_defs(d):
|
||||||
|
# Note: `or ''` below is required because `module_path` could be
|
||||||
|
# None and you can't compare None and str in Python 3.
|
||||||
|
return sorted(d, key=lambda x: (x.module_path or '', x.start_pos))
|
||||||
|
|
||||||
|
|
||||||
def defined_names(source, source_path=None, source_encoding='utf-8'):
|
def defined_names(source, source_path=None, source_encoding='utf-8'):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user