From d7face17f6e082f466ba3b6f6aba959fe4133a9c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 17 Oct 2014 12:03:41 +0200 Subject: [PATCH] Using expr_stmt now instead of simple_stmt as ExprStmt, because that resembles the official grammar better. --- jedi/parser/pytree.py | 5 +++-- jedi/parser/representation.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/jedi/parser/pytree.py b/jedi/parser/pytree.py index 75aa6ed2..2db96318 100644 --- a/jedi/parser/pytree.py +++ b/jedi/parser/pytree.py @@ -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() diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 30adddd5..4cf2021e 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -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