forked from VimPlug/jedi
Using expr_stmt now instead of simple_stmt as ExprStmt, because that resembles the official grammar better.
This commit is contained in:
@@ -25,7 +25,6 @@ _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "grammar3.4.txt")
|
||||
|
||||
|
||||
class Symbols(object):
|
||||
|
||||
def __init__(self, grammar):
|
||||
"""Initializer.
|
||||
|
||||
@@ -95,7 +94,9 @@ def convert(grammar, raw_node):
|
||||
if type in grammar.number2symbol:
|
||||
# If there's exactly one child, return that child instead of
|
||||
# creating a new node.
|
||||
if len(children) == 1 and type != 'expr_stmt':
|
||||
# We still create expr_stmt though, because a lot of Jedi depends on
|
||||
# its logic.
|
||||
if len(children) == 1 and type != python_symbols.expr_stmt:
|
||||
return children[0]
|
||||
print(raw_node, type_repr(type))
|
||||
#import pdb; pdb.set_trace()
|
||||
|
||||
@@ -42,6 +42,7 @@ import os
|
||||
import re
|
||||
from inspect import cleandoc
|
||||
from collections import defaultdict
|
||||
from itertools import chain
|
||||
|
||||
from jedi._compatibility import (next, Python3Method, encoding, unicode,
|
||||
is_py3, u, literal_eval, use_metaclass)
|
||||
@@ -400,7 +401,9 @@ class Scope(Simple, DocstringMixin):
|
||||
|
||||
@property
|
||||
def statements(self):
|
||||
return [c for c in self.children if isinstance(c, ExprStmt)]
|
||||
return [s for c in self.children if is_node(c, 'simple_stmt')
|
||||
for s in c.children if isinstance(s, (ExprStmt, Import,
|
||||
KeywordStatement))]
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
@@ -460,8 +463,10 @@ class Scope(Simple, DocstringMixin):
|
||||
"""
|
||||
names = []
|
||||
for c in self.children:
|
||||
if isinstance(c, ExprStmt):
|
||||
names += c.get_defined_names()
|
||||
if is_node(c, 'simple_stmt'):
|
||||
names += chain.from_iterable(
|
||||
[s.get_defined_names() for s in c.children
|
||||
if isinstance(s, (ExprStmt, Import, KeywordStatement))])
|
||||
elif isinstance(c, (Function, Class)):
|
||||
names.append(c.name)
|
||||
return names
|
||||
|
||||
Reference in New Issue
Block a user