mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Removed Scope.statements from the parser tree.
This commit is contained in:
@@ -273,13 +273,15 @@ class Scope(PythonBaseNode, DocstringMixin):
|
|||||||
|
|
||||||
return scan(self.children)
|
return scan(self.children)
|
||||||
|
|
||||||
@property
|
|
||||||
def statements(self):
|
|
||||||
return self._search_in_scope((ExprStmt, KeywordStatement))
|
|
||||||
|
|
||||||
def is_scope(self):
|
def is_scope(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_suite(self):
|
||||||
|
"""
|
||||||
|
Returns the part that is executed by the function.
|
||||||
|
"""
|
||||||
|
return self.children[-1]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
try:
|
try:
|
||||||
name = self.name.value
|
name = self.name.value
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ from jedi import Script
|
|||||||
def test_paths_from_assignment():
|
def test_paths_from_assignment():
|
||||||
def paths(src):
|
def paths(src):
|
||||||
script = Script(src)
|
script = Script(src)
|
||||||
stmt = script._get_module_node().statements[0]
|
expr_stmt = script._get_module_node().children[0].children[0]
|
||||||
return set(sys_path._paths_from_assignment(script._get_module(), stmt))
|
return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
|
||||||
|
|
||||||
assert paths('sys.path[0:0] = ["a"]') == set(['a'])
|
assert paths('sys.path[0:0] = ["a"]') == set(['a'])
|
||||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == set(['b', 'c'])
|
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == set(['b', 'c'])
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def test_carriage_return_statements():
|
|||||||
# this is a namespace package
|
# this is a namespace package
|
||||||
''')
|
''')
|
||||||
source = source.replace('\n', '\r\n')
|
source = source.replace('\n', '\r\n')
|
||||||
stmt = parse(source).statements[0]
|
stmt = parse(source).children[0]
|
||||||
assert '#' not in stmt.get_code()
|
assert '#' not in stmt.get_code()
|
||||||
|
|
||||||
|
|
||||||
@@ -120,7 +120,9 @@ def test_incomplete_list_comprehension():
|
|||||||
""" Shouldn't raise an error, same bug as #418. """
|
""" Shouldn't raise an error, same bug as #418. """
|
||||||
# With the old parser this actually returned a statement. With the new
|
# With the old parser this actually returned a statement. With the new
|
||||||
# parser only valid statements generate one.
|
# parser only valid statements generate one.
|
||||||
assert parse('(1 for def').statements == []
|
children = parse('(1 for def').children
|
||||||
|
assert [c.type for c in children] == \
|
||||||
|
['error_node', 'error_node', 'newline', 'endmarker']
|
||||||
|
|
||||||
|
|
||||||
def test_hex_values_in_docstring():
|
def test_hex_values_in_docstring():
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ class TokenTest(unittest.TestCase):
|
|||||||
def testit():
|
def testit():
|
||||||
a = "huhu"
|
a = "huhu"
|
||||||
'''))
|
'''))
|
||||||
tok = parsed.subscopes[0].statements[0].children[2]
|
simple_stmt = parsed.subscopes[0].get_suite().children[-1]
|
||||||
assert tok.end_pos == (3, 14)
|
string = simple_stmt.children[0].get_rhs()
|
||||||
|
assert string.end_pos == (3, 14)
|
||||||
|
|
||||||
def test_end_pos_multi_line(self):
|
def test_end_pos_multi_line(self):
|
||||||
parsed = parse(dedent('''
|
parsed = parse(dedent('''
|
||||||
@@ -32,8 +33,9 @@ class TokenTest(unittest.TestCase):
|
|||||||
a = """huhu
|
a = """huhu
|
||||||
asdfasdf""" + "h"
|
asdfasdf""" + "h"
|
||||||
'''))
|
'''))
|
||||||
tok = parsed.subscopes[0].statements[0].children[2].children[0]
|
expr_stmt = parsed.subscopes[0].get_suite().children[1].children[0]
|
||||||
assert tok.end_pos == (4, 11)
|
string_leaf = expr_stmt.get_rhs().children[0]
|
||||||
|
assert string_leaf.end_pos == (4, 11)
|
||||||
|
|
||||||
def test_simple_no_whitespace(self):
|
def test_simple_no_whitespace(self):
|
||||||
# Test a simple one line string, no preceding whitespace
|
# Test a simple one line string, no preceding whitespace
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ class TestRegression(TestCase):
|
|||||||
# jedi issue #150
|
# jedi issue #150
|
||||||
s = "x()\nx( )\nx( )\nx ( )"
|
s = "x()\nx( )\nx( )\nx ( )"
|
||||||
module = parse(s)
|
module = parse(s)
|
||||||
for i, s in enumerate(module.statements):
|
for i, simple_stmt in enumerate(module.children[:-1]):
|
||||||
assert s.end_pos == (i + 1, i + 3)
|
expr_stmt = simple_stmt.children[0]
|
||||||
|
assert expr_stmt.end_pos == (i + 1, i + 3)
|
||||||
|
|
||||||
def check_definition_by_marker(self, source, after_cursor, names):
|
def check_definition_by_marker(self, source, after_cursor, names):
|
||||||
r"""
|
r"""
|
||||||
|
|||||||
Reference in New Issue
Block a user