Skip to content

Commit 0dad706

Browse files
committed
more correct error messages for weakrefs
1 parent dcfabfd commit 0dad706

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ public int hash(PReferenceType self) {
103103
return self.getHash();
104104
}
105105

106-
@Fallback
107-
public int hash(@SuppressWarnings("unused") Object self) {
106+
@Specialization(guards = "self.getObject() == null")
107+
public int hashGone(@SuppressWarnings("unused") PReferenceType self) {
108108
throw raise(PythonErrorType.TypeError, "weak object has gone away");
109109
}
110+
111+
@Fallback
112+
public int hashWrong(@SuppressWarnings("unused") Object self) {
113+
throw raise(PythonErrorType.TypeError, "descriptor '__hash__' requires a 'weakref' object but received a '%p'", self);
114+
}
110115
}
111116

112117
// ref.__repr__

0 commit comments

Comments
 (0)