Skip to content

Commit

Permalink
keyword statement not includes globals
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Mar 4, 2014
1 parent f4b235a commit 2322edf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions jedi/evaluate/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def _remove_statements(self, stmt):
types = []
if stmt.is_global():
# global keyword handling.
for token_name in stmt._token_list[1:]:
for token_name in stmt._token_list:
if isinstance(token_name, pr.Name):
return evaluator.find_types(stmt.parent, str(token_name))
return evaluator.find_types(stmt.parent.parent, str(token_name))
else:
# Remove the statement docstr stuff for now, that has to be
# implemented with the evaluator class.
Expand Down
21 changes: 8 additions & 13 deletions jedi/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,26 +563,21 @@ class description.
stmt.start_pos = s
except AttributeError:
debug.warning('return in non-function')
# globals
elif tok_str == 'global':
stmt, tok = self._parse_statement(self._gen.current)
if stmt:
self._scope.add_statement(stmt)
for t in stmt._token_list:
if isinstance(t, pr.Name):
# add the global to the top, because there it is
# important.
self.module.add_global(t)
elif tok_str == 'assert':
stmt, tok = self._parse_statement()
if stmt is not None:
stmt.parent = use_as_parent_scope
self._scope.asserts.append(stmt)
elif tok_str in STATEMENT_KEYWORDS:
stmt, _ = self._parse_statement()
k = pr.KeywordStatement(tok_str, tok.start_pos,
use_as_parent_scope, stmt)
self._scope.add_statement(k)
kw = pr.KeywordStatement(tok_str, tok.start_pos,
use_as_parent_scope, stmt)
self._scope.add_statement(kw)
if stmt is not None and tok_str == 'global':
for t in stmt._token_list:
if isinstance(t, pr.Name):
# Add the global to the top module, it counts there.
self.module.add_global(t)
# decorator
elif tok_str == '@':
stmt, tok = self._parse_statement()
Expand Down
5 changes: 2 additions & 3 deletions jedi/parser/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,8 @@ def search_calls(calls):
return self._set_vars + self.as_names

def is_global(self):
# first keyword of the first token is global -> must be a global
tok = self._token_list[0]
return isinstance(tok, Name) and str(tok) == "global"
p = self.parent
return isinstance(p, KeywordStatement) and p.name == 'global'

@property
def assignment_details(self):
Expand Down

0 comments on commit 2322edf

Please sign in to comment.