mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-11 00:01:54 +08:00
Writing a different Name.get_definition() implementation, returns the node, if there's no expr_stmt parent.
This commit is contained in:
@@ -546,7 +546,11 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
||||
elif isinstance(d, pr.Param):
|
||||
d = d.get_code()
|
||||
else: # ExprStmt
|
||||
try:
|
||||
first_leaf = d.first_leaf()
|
||||
except AttributeError:
|
||||
# `d` is already a Leaf (Name).
|
||||
first_leaf = d
|
||||
# Remove the prefix, because that's not what we want for get_code
|
||||
# here.
|
||||
old, first_leaf.prefix = first_leaf.prefix, ''
|
||||
|
||||
@@ -272,18 +272,19 @@ class Name(Leaf):
|
||||
self.start_pos[0], self.start_pos[1])
|
||||
|
||||
def get_definition(self):
|
||||
scope = self.parent
|
||||
scope = self
|
||||
while scope.parent is not None:
|
||||
if scope.isinstance(Node):
|
||||
parent = scope.parent
|
||||
if scope.isinstance(Node, Name) and parent.type != 'simple_stmt':
|
||||
if scope.type == 'testlist_comp':
|
||||
try:
|
||||
if isinstance(scope.children[1], CompFor):
|
||||
return scope.children[1]
|
||||
except IndexError:
|
||||
pass
|
||||
scope = parent
|
||||
else:
|
||||
break
|
||||
scope = scope.parent
|
||||
return scope
|
||||
|
||||
def is_definition(self):
|
||||
|
||||
Reference in New Issue
Block a user