diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java index e3e8efeb0052..69deadc25cb7 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java @@ -136,7 +136,7 @@ public class ScopeImpl implements Scope { if (myNamedElements == null || myImportedNameDefiners == null) { collectDeclarations(); } - if (isNonlocal(name)) { + if (isNonlocal(name) || isGlobal(name)) { return false; } if (!getNamedElements(name, true).isEmpty()) { diff --git a/python/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java b/python/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java index c9a4403a06fb..b121e5596727 100644 --- a/python/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java @@ -270,7 +270,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference final ScopeOwner resolvedOwner = processor.getOwner(); final Collection resolvedElements = processor.getElements(); - if (resolvedOwner != null && !resolvedElements.isEmpty() && !ControlFlowCache.getScope(resolvedOwner).isGlobal(referencedName)) { + if (resolvedOwner != null && !resolvedElements.isEmpty()) { if (resolvedOwner == referenceOwner) { final List instructions = getLatestDefinitions(referencedName, resolvedOwner, realContext); // TODO: Use the results from the processor as a cache for resolving to latest defs diff --git a/python/testData/resolve/GlobalReassignmentNotDefinedAtTopLevel.py b/python/testData/resolve/GlobalReassignmentNotDefinedAtTopLevel.py new file mode 100644 index 000000000000..a0a7089c1a69 --- /dev/null +++ b/python/testData/resolve/GlobalReassignmentNotDefinedAtTopLevel.py @@ -0,0 +1,4 @@ +def f(): + global xx + xx = 2 +# diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index e6abb79e408c..7218b5dfed31 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -754,11 +754,15 @@ public class PyResolveTest extends PyResolveTestCase { assertEquals("2", target.getText()); } - public void testGlobalNotDefinedAtTopLevel() { assertResolvesTo(PyTargetExpression.class, "foo"); } + public void testGlobalReassignmentNotDefinedAtTopLevel() { + final PyTargetExpression target = assertResolvesTo(PyTargetExpression.class, "xx"); + assertInstanceOf(target.getParent(), PyGlobalStatement.class); + } + // PY-13734 public void testImplicitDunderClass() { assertUnresolved();