mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-16 10:37:52 +08:00
Replace Scope.subscopes with iter_funcdefs and iter_classdefs.
This commit is contained in:
@@ -15,7 +15,7 @@ def assert_params(param_string, **wanted_dct):
|
||||
''') % param_string
|
||||
|
||||
module = parse(source)
|
||||
funcdef = module.subscopes[0]
|
||||
funcdef = next(module.iter_funcdefs())
|
||||
dct = dict((p.name.value, p.default and p.default.get_code())
|
||||
for p in funcdef.params)
|
||||
assert dct == wanted_dct
|
||||
|
||||
@@ -63,7 +63,7 @@ class TestCallAndName():
|
||||
|
||||
class TestSubscopes():
|
||||
def get_sub(self, source):
|
||||
return parse(source).subscopes[0]
|
||||
return parse(source).children[0]
|
||||
|
||||
def test_subscope_names(self):
|
||||
name = self.get_sub('class Foo: pass').name
|
||||
@@ -100,7 +100,7 @@ def test_end_pos():
|
||||
y = None
|
||||
''')
|
||||
parser = parse(s)
|
||||
scope = parser.subscopes[0]
|
||||
scope = next(parser.iter_funcdefs())
|
||||
assert scope.start_pos == (3, 0)
|
||||
assert scope.end_pos == (5, 0)
|
||||
|
||||
@@ -134,7 +134,7 @@ def test_hex_values_in_docstring():
|
||||
return 1
|
||||
'''
|
||||
|
||||
doc = clean_scope_docstring(parse(source).subscopes[0])
|
||||
doc = clean_scope_docstring(next(parse(source).iter_funcdefs()))
|
||||
if is_py3:
|
||||
assert doc == '\xff'
|
||||
else:
|
||||
@@ -184,12 +184,12 @@ def test_param_splitting():
|
||||
grammar = load_grammar('%s.%s' % sys.version_info[:2])
|
||||
m = parse(src, grammar=grammar)
|
||||
if is_py3:
|
||||
assert not m.subscopes
|
||||
assert not list(m.iter_funcdefs())
|
||||
else:
|
||||
# We don't want b and c to be a part of the param enumeration. Just
|
||||
# ignore them, because it's not what we want to support in the
|
||||
# future.
|
||||
assert [param.name.value for param in m.subscopes[0].params] == result
|
||||
assert [param.name.value for param in next(m.iter_funcdefs()).params] == result
|
||||
|
||||
check('def x(a, (b, c)):\n pass', ['a'])
|
||||
check('def x((b, c)):\n pass', [])
|
||||
|
||||
@@ -29,7 +29,10 @@ class TestsFunctionAndLambdaParsing(object):
|
||||
def node(self, request):
|
||||
parsed = parse(dedent(request.param[0]))
|
||||
request.keywords['expected'] = request.param[1]
|
||||
return parsed.subscopes[0]
|
||||
child = parsed.children[0]
|
||||
if child.type == 'simple_stmt':
|
||||
child = child.children[0]
|
||||
return child
|
||||
|
||||
@pytest.fixture()
|
||||
def expected(self, request, node):
|
||||
|
||||
@@ -23,7 +23,7 @@ class TokenTest(unittest.TestCase):
|
||||
def testit():
|
||||
a = "huhu"
|
||||
'''))
|
||||
simple_stmt = parsed.subscopes[0].get_suite().children[-1]
|
||||
simple_stmt = next(parsed.iter_funcdefs()).get_suite().children[-1]
|
||||
string = simple_stmt.children[0].get_rhs()
|
||||
assert string.end_pos == (3, 14)
|
||||
|
||||
@@ -33,7 +33,7 @@ class TokenTest(unittest.TestCase):
|
||||
a = """huhu
|
||||
asdfasdf""" + "h"
|
||||
'''))
|
||||
expr_stmt = parsed.subscopes[0].get_suite().children[1].children[0]
|
||||
expr_stmt = next(parsed.iter_funcdefs()).get_suite().children[1].children[0]
|
||||
string_leaf = expr_stmt.get_rhs().children[0]
|
||||
assert string_leaf.end_pos == (4, 11)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user