Skip to content

Commit 78efe9f

Browse files
committed
[GR-23236] Fix test_genexps.
PullRequest: graalpython/1189
2 parents 791d48d + 8de6a3e commit 78efe9f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/FactorySSTVisitor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.Map;
5858

5959
import com.oracle.graal.python.PythonLanguage;
60+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
6061
import com.oracle.graal.python.builtins.objects.PEllipsis;
6162
import com.oracle.graal.python.builtins.objects.PNone;
6263
import com.oracle.graal.python.builtins.objects.complex.PComplex;
@@ -347,8 +348,12 @@ public PNode visit(AugAssignmentSSTNode node) {
347348

348349
private void checkCannotAssignTo(SSTNode lhs) throws RuntimeException {
349350
if (lhs instanceof ForComprehensionSSTNode) {
351+
PythonBuiltinClassType resultType = ((ForComprehensionSSTNode) lhs).resultType;
352+
if (resultType == PythonBuiltinClassType.PGenerator) {
353+
throw errors.raiseInvalidSyntax(source, createSourceSection(lhs.startOffset, lhs.endOffset), "cannot assign to generator expression");
354+
}
350355
String calleeName;
351-
switch (((ForComprehensionSSTNode) lhs).resultType) {
356+
switch (resultType) {
352357
case PList:
353358
calleeName = BuiltinNames.LIST;
354359
break;

graalpython/lib-python/3/test/test_genexps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@
127127
[(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3)]
128128
129129
Verify re-use of tuples (a side benefit of using genexps over listcomps)
130+
(Note: CPython keeps a free list of small tuples and reuses them.
131+
This CPython specific optimization check is skipped in GraalPython.)
130132
131133
>>> tupleids = list(map(id, ((i,i) for i in range(10))))
132-
>>> int(max(tupleids) - min(tupleids))
134+
>>> int(max(tupleids) - min(tupleids)) # doctest: +SKIP
133135
0
134136
135137
Verify that syntax error's are raised for genexps used as lvalues

0 commit comments

Comments
 (0)