Skip to content

Commit 8b3a3d0

Browse files
committed
Add missing __hash__ method to method types
1 parent ba719f2 commit 8b3a3d0

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__SELF__;
3434
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
3535
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
36+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
3637

3738
import java.util.List;
3839

@@ -137,6 +138,20 @@ boolean eq(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused")
137138
}
138139
}
139140

141+
@Builtin(name = __HASH__, minNumOfPositionalArgs = 2)
142+
@GenerateNodeFactory
143+
abstract static class HashNode extends PythonUnaryBuiltinNode {
144+
@Specialization
145+
static long hash(PMethod self) {
146+
return self.hash();
147+
}
148+
149+
@Specialization
150+
static long hash(PBuiltinMethod self) {
151+
return self.hash();
152+
}
153+
}
154+
140155
@Builtin(name = __MODULE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
141156
@GenerateNodeFactory
142157
abstract static class GetModuleNode extends PythonBinaryBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PBuiltinMethod.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ boolean isHashable() {
7474
return true;
7575
}
7676

77+
public long hash() {
78+
return PythonAbstractObject.systemHashCode(this.getSelf()) ^ PythonAbstractObject.systemHashCode(this.getFunction());
79+
}
80+
7781
@ExportMessage
7882
protected long hashWithState(@SuppressWarnings("unused") ThreadState state) {
79-
return PythonAbstractObject.systemHashCode(this.getSelf()) ^ PythonAbstractObject.systemHashCode(this.getFunction());
83+
return hash();
8084
}
8185
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/PMethod.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ boolean isHashable() {
8787
return true;
8888
}
8989

90+
public long hash() {
91+
return PythonAbstractObject.systemHashCode(this.getSelf()) ^ PythonAbstractObject.systemHashCode(this.getFunction());
92+
}
93+
9094
@ExportMessage
9195
protected long hashWithState(@SuppressWarnings("unused") ThreadState state) {
92-
return PythonAbstractObject.systemHashCode(this.getSelf()) ^ PythonAbstractObject.systemHashCode(this.getFunction());
96+
return hash();
9397
}
9498
}

0 commit comments

Comments
 (0)