mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Add a Name.get_parent_stmt() function.
This commit is contained in:
@@ -154,7 +154,7 @@ class BaseDefinition(object):
|
|||||||
if isinstance(stripped, iterable.Array):
|
if isinstance(stripped, iterable.Array):
|
||||||
return 'instance'
|
return 'instance'
|
||||||
string = type(stripped).__name__.lower().replace('wrapper', '')
|
string = type(stripped).__name__.lower().replace('wrapper', '')
|
||||||
if string == 'exprstatement':
|
if string == 'exprstmt':
|
||||||
return 'statement'
|
return 'statement'
|
||||||
else:
|
else:
|
||||||
return string
|
return string
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class Parser(object):
|
|||||||
# Classes don't have params, a Class works more like a function
|
# Classes don't have params, a Class works more like a function
|
||||||
# call.
|
# call.
|
||||||
param, tok = self._parse_statement(added_breaks=breaks,
|
param, tok = self._parse_statement(added_breaks=breaks,
|
||||||
stmt_class=pr.ExprStatement
|
stmt_class=pr.ExprStmt
|
||||||
if is_class else pr.Param)
|
if is_class else pr.Param)
|
||||||
if is_class:
|
if is_class:
|
||||||
if param is not None:
|
if param is not None:
|
||||||
@@ -280,7 +280,7 @@ class Parser(object):
|
|||||||
return pr.Class(self.module, cname, superclasses, first_pos)
|
return pr.Class(self.module, cname, superclasses, first_pos)
|
||||||
|
|
||||||
def _parse_statement(self, pre_used_token=None, added_breaks=None,
|
def _parse_statement(self, pre_used_token=None, added_breaks=None,
|
||||||
stmt_class=pr.ExprStatement, names_are_set_vars=False,
|
stmt_class=pr.ExprStmt, names_are_set_vars=False,
|
||||||
maybe_docstr=False):
|
maybe_docstr=False):
|
||||||
"""
|
"""
|
||||||
Parses statements like::
|
Parses statements like::
|
||||||
@@ -292,8 +292,8 @@ class Parser(object):
|
|||||||
|
|
||||||
:param pre_used_token: The pre parsed token.
|
:param pre_used_token: The pre parsed token.
|
||||||
:type pre_used_token: set
|
:type pre_used_token: set
|
||||||
:return: ExprStatement + last parsed token.
|
:return: ExprStmt + last parsed token.
|
||||||
:rtype: (ExprStatement, str)
|
:rtype: (ExprStmt, str)
|
||||||
"""
|
"""
|
||||||
set_vars = []
|
set_vars = []
|
||||||
level = 0 # The level of parentheses
|
level = 0 # The level of parentheses
|
||||||
|
|||||||
@@ -1223,7 +1223,7 @@ class Statement(Simple, DocstringMixin):
|
|||||||
self._expression_list = lst
|
self._expression_list = lst
|
||||||
|
|
||||||
|
|
||||||
class ExprStatement(Statement):
|
class ExprStmt(Statement):
|
||||||
"""
|
"""
|
||||||
This class exists temporarily, to be able to distinguish real statements
|
This class exists temporarily, to be able to distinguish real statements
|
||||||
(``small_stmt`` in Python grammar) from the so called ``test`` parts, that
|
(``small_stmt`` in Python grammar) from the so called ``test`` parts, that
|
||||||
@@ -1235,7 +1235,7 @@ class ExprStatement(Statement):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Param(ExprStatement):
|
class Param(ExprStmt):
|
||||||
"""
|
"""
|
||||||
The class which shows definitions of params of classes and functions.
|
The class which shows definitions of params of classes and functions.
|
||||||
But this is not to define function calls.
|
But this is not to define function calls.
|
||||||
@@ -1463,6 +1463,9 @@ class NamePart(object):
|
|||||||
def get_code(self):
|
def get_code(self):
|
||||||
return self._string
|
return self._string
|
||||||
|
|
||||||
|
def get_parent_stmt(self):
|
||||||
|
return self.parent.parent_stmt()
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
return self.parent.get_parent_until(*args, **kwargs)
|
return self.parent.get_parent_until(*args, **kwargs)
|
||||||
|
|
||||||
@@ -1501,6 +1504,9 @@ class Name(Simple):
|
|||||||
""" Returns the names in a full string format """
|
""" Returns the names in a full string format """
|
||||||
return self._get_code
|
return self._get_code
|
||||||
|
|
||||||
|
def get_parent_stmt(self):
|
||||||
|
return self.get_parent_until(ExprStmt)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end_pos(self):
|
def end_pos(self):
|
||||||
return self.names[-1].end_pos
|
return self.names[-1].end_pos
|
||||||
|
|||||||
Reference in New Issue
Block a user