Skip to content

Commit ba7824e

Browse files
committed
[GR-23296] Get test_global to pass.
PullRequest: graalpython/1267
2 parents 4841ac9 + c2bf9c2 commit ba7824e

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*graalpython.lib-python.3.test.test_global.GlobalTests.test1
2+
*graalpython.lib-python.3.test.test_global.GlobalTests.test2
23
*graalpython.lib-python.3.test.test_global.GlobalTests.test3
34
*graalpython.lib-python.3.test.test_global.GlobalTests.test4
5+
*graalpython.lib-python.3.test.test_global.TestMain.test_main

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ public abstract class ErrorMessages {
362362
public static final String MUST_BE_TUPLE_OF_CLASSES_NOT_P = "%s.%s must be tuple of classes, not '%p'";
363363
public static final String MUST_SPECIFY_FILTERS = "Must specify filters for FORMAT_RAW";
364364
public static final String MUTATED_DURING_UPDATE = "%s mutated during update";
365+
public static final String NAME_IS_USED_BEFORE_GLOBAL = "name '%s' is used prior to global declaration";
365366
public static final String NAME_IS_ASSIGNED_BEFORE_GLOBAL = "name '%s' is assigned to before global declaration";
366367
public static final String NAME_IS_ASSIGNED_BEFORE_NONLOCAL = "name '%s' is assigned to before nonlocal declaration";
367368
public static final String NAME_NOT_DEFINED = "name '%s' is not defined";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonSSTNodeFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public SSTNode registerGlobal(String[] names, int startOffset, int endOffset) {
160160
// The slot is created by assignment or declaration
161161
throw errors.raiseInvalidSyntax(source, createSourceSection(startOffset, endOffset), ErrorMessages.NAME_IS_ASSIGNED_BEFORE_GLOBAL, name);
162162
}
163+
if (scopeInfo.getSeenVars() != null && scopeInfo.getSeenVars().contains(name)) {
164+
throw errors.raiseInvalidSyntax(source, createSourceSection(startOffset, endOffset), ErrorMessages.NAME_IS_USED_BEFORE_GLOBAL, name);
165+
}
163166
scopeInfo.addExplicitGlobalVariable(name);
164167
// place the global variable into global space, see test_global_statemnt.py
165168
globalScope.addExplicitGlobalVariable(name);

graalpython/lib-graalpython/unicodedata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444

4545
@__graalpython__.builtin
4646
def __get_c_unicodedata():
47+
global c_unicodedata_module
4748
if c_unicodedata_module is None:
4849
import _cpython_unicodedata
49-
global c_unicodedata_module
5050
c_unicodedata_module = _cpython_unicodedata
5151
return c_unicodedata_module
5252

0 commit comments

Comments
 (0)