From 469d6940a7b8d509d5e1e6d2ecfe53e492205b70 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 12 Nov 2016 13:11:54 +0100 Subject: [PATCH] Fix global statements. --- jedi/evaluate/finder.py | 26 ++++++++------------------ jedi/evaluate/representation.py | 11 ----------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 3ce8b6e3..37919d65 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -19,7 +19,6 @@ from itertools import chain from jedi._compatibility import unicode from jedi.parser import tree from jedi import debug -from jedi import common from jedi.common import unite from jedi import settings from jedi.evaluate import representation as er @@ -227,7 +226,7 @@ class NameFinder(object): # TODO seriously? this is stupid. continue check = flow_analysis.reachability_check(self._context, name_scope, - stmt, origin_scope) + stmt, origin_scope) if check is not flow_analysis.UNREACHABLE: last_names.append(name) @@ -339,15 +338,6 @@ class NameFinder(object): return result -def _get_global_stmt_scopes(evaluator, global_stmt, name): - raise DeprecationWarning - global_stmt_scope = global_stmt.get_parent_scope() - module = global_stmt_scope.get_parent_until() - for used_name in module.used_names[str(name)]: - if used_name.parent.type == 'global_stmt': - yield evaluator.wrap(used_name.get_parent_scope()) - - @memoize_default(set(), evaluator_is_first_arg=True) def _name_to_types(evaluator, context, name, scope): types = [] @@ -376,13 +366,13 @@ def _name_to_types(evaluator, context, name, scope): elif node.type in ('funcdef', 'classdef'): types = _apply_decorators(evaluator, context, node) elif node.type == 'global_stmt': - for s in _get_global_stmt_scopes(evaluator, node, name): - finder = NameFinder(evaluator, s, str(name)) - names_dicts = finder.get_filters(search_global=True) - # For global_stmt lookups, we only need the first possible scope, - # which means the function itself. - names_dicts = [next(names_dicts)] - types += finder.find(names_dicts, attribute_lookup=False) + context = evaluator.create_context(context, name) + finder = NameFinder(evaluator, context, str(name)) + filters = finder.get_filters(search_global=True) + # For global_stmt lookups, we only need the first possible scope, + # which means the function itself. + filters = [next(filters)] + types += finder.find(filters, attribute_lookup=False) elif isinstance(node, tree.TryStmt): # TODO an exception can also be a tuple. Check for those. # TODO check for types that are not classes and add it to diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 9679c202..dad77b73 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -736,17 +736,6 @@ class AnonymousFunctionExecution(FunctionExecutionContext): return search_params(self.evaluator, self.parent_context, self.funcdef) -class GlobalName(object): - def __init__(self, name): - """ - We need to mark global names somehow. Otherwise they are just normal - names that are not definitions. - """ - raise NotImplementedError - super(GlobalName, self).__init__(name.value, name.parent, - name.start_pos, is_definition=True) - - class ModuleAttributeName(AbstractNameDefinition): """ For module attributes like __file__, __str__ and so on.