Skip to content

Commit dea734c

Browse files
committed
Fix generator repr
1 parent 67ad7ab commit dea734c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CoroutineBuiltins.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.graal.python.builtins.objects.generator;
4242

4343
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___AWAIT__;
44+
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___REPR__;
4445

4546
import java.util.List;
4647

@@ -49,6 +50,8 @@
4950
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
5051
import com.oracle.graal.python.builtins.PythonBuiltins;
5152
import com.oracle.graal.python.builtins.objects.PNone;
53+
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
54+
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
5255
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5356
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5457
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -60,6 +63,7 @@
6063
import com.oracle.truffle.api.frame.VirtualFrame;
6164
import com.oracle.truffle.api.nodes.Node;
6265
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
66+
import com.oracle.truffle.api.strings.TruffleString;
6367

6468
@CoreFunctions(extendClasses = PythonBuiltinClassType.PCoroutine)
6569
public final class CoroutineBuiltins extends PythonBuiltins {
@@ -127,4 +131,14 @@ static Object await(PGenerator self,
127131
return factory.createCoroutineWrapper(self);
128132
}
129133
}
134+
135+
@Builtin(name = J___REPR__, minNumOfPositionalArgs = 1)
136+
@GenerateNodeFactory
137+
abstract static class ReprNode extends PythonUnaryBuiltinNode {
138+
@Specialization
139+
static TruffleString repr(PGenerator self,
140+
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode) {
141+
return simpleTruffleStringFormatNode.format("<coroutine object %s at 0x%d>", self.getQualname(), PythonAbstractObject.objectHashCode(self));
142+
}
143+
}
130144
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ abstract static class ReprNode extends PythonUnaryBuiltinNode {
224224
@Specialization
225225
static TruffleString repr(PGenerator self,
226226
@Cached SimpleTruffleStringFormatNode simpleTruffleStringFormatNode) {
227-
return simpleTruffleStringFormatNode.format("<generator object %s at %d>", self.getName(), PythonAbstractObject.objectHashCode(self));
227+
return simpleTruffleStringFormatNode.format("<generator object %s at 0x%d>", self.getQualname(), PythonAbstractObject.objectHashCode(self));
228228
}
229229
}
230230

0 commit comments

Comments
 (0)