Skip to content

Commit d8e1ab7

Browse files
committed
fix __repr__ message for ReferenceType instances
1 parent e5cfb7d commit d8e1ab7

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WeakRefModuleBuiltins.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.python.builtins.objects.function.PFunction;
4949
import com.oracle.graal.python.builtins.objects.object.PythonObject;
5050
import com.oracle.graal.python.builtins.objects.referencetype.PReferenceType;
51+
import com.oracle.graal.python.builtins.objects.type.PythonClass;
5152
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5253
import com.oracle.graal.python.runtime.exception.PythonErrorType;
5354
import com.oracle.truffle.api.dsl.Fallback;
@@ -67,19 +68,18 @@ protected List<? extends NodeFactory<? extends PythonBuiltinNode>> getNodeFactor
6768
@Builtin(name = "ReferenceType", minNumOfArguments = 2, maxNumOfArguments = 3, constructsClass = PReferenceType.class)
6869
@GenerateNodeFactory
6970
public abstract static class ReferenceTypeNode extends PythonBuiltinNode {
70-
7171
@Specialization
72-
public PReferenceType refType(Object cls, PythonObject pythonObject, PNone none) {
73-
return factory().createReferenceType(pythonObject, null);
72+
public PReferenceType refType(PythonClass cls, PythonObject pythonObject, PNone none) {
73+
return factory().createReferenceType(cls, pythonObject, null);
7474
}
7575

7676
@Specialization
77-
public PReferenceType refType(Object cls, PythonObject pythonObject, PFunction callback) {
78-
return factory().createReferenceType(pythonObject, callback);
77+
public PReferenceType refType(PythonClass cls, PythonObject pythonObject, PFunction callback) {
78+
return factory().createReferenceType(cls, pythonObject, callback);
7979
}
8080

8181
@Fallback
82-
public PReferenceType refType(@SuppressWarnings("unused") Object cls, @SuppressWarnings("unused") Object object, @SuppressWarnings("unused") Object callback) {
82+
public PReferenceType refType(Object cls, Object object, Object callback) {
8383
throw raise(PythonErrorType.TypeError, "cannot create weak reference to '%p' object", object);
8484
}
8585
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/referencetype/ReferenceTypeBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public String repr(PReferenceType self,
122122
Object object = self.getObject();
123123
Object name = getNameNode.execute(object, __NAME__);
124124
if (name == PNone.NO_VALUE) {
125-
return String.format("<weakref at %s; to '%s' at %s>", self.hashCode(), object, object.hashCode());
125+
return String.format("<weakref at %s; to '%s' at %s>", self.hashCode(), object.hashCode(), object.hashCode());
126126
} else {
127-
return String.format("<weakref at %s; to '%s' at %s (%s)>", self.hashCode(), object, object.hashCode(), name);
127+
return String.format("<weakref at %s; to '%s' at %s (%s)>", self.hashCode(), name, object.hashCode(), object);
128128
}
129129
}
130130
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,12 @@ public PMappingproxy createMappingproxy(PythonClass cls, PythonObject object) {
489489
return trace(new PMappingproxy(cls, object));
490490
}
491491

492+
public PReferenceType createReferenceType(PythonClass cls, PythonObject object, PFunction callback) {
493+
return trace(new PReferenceType(cls, object, callback));
494+
}
495+
492496
public PReferenceType createReferenceType(PythonObject object, PFunction callback) {
493-
return trace(new PReferenceType(lookupClass(PythonBuiltinClassType.PReferenceType), object, callback));
497+
return createReferenceType(lookupClass(PythonBuiltinClassType.PReferenceType), object, callback);
494498
}
495499

496500
/*

0 commit comments

Comments
 (0)