diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 19e79553..bf0f67e5 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -686,6 +686,11 @@ def tree_name_to_values(inference_state, context, tree_name): node = tree_name.parent if node.type == 'global_stmt': c = context.create_context(tree_name) + if c.is_module(): + # In case we are already part of the module, there is no point + # in looking up the global statement anymore, because it's not + # valid at that point anyway. + return NO_VALUES # For global_stmt lookups, we only need the first possible scope, # which means the function itself. filter = next(c.get_filters()) diff --git a/test/completion/basic.py b/test/completion/basic.py index 2c2be9b6..87c530da 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -196,6 +196,13 @@ def global_as_import(): globals.foo +global r +r = r[r] +if r: + r += r + 2 + #? int() + r + # ----------------- # within docstrs # -----------------