Skip to content

Missing descriptor for __hash__ in __slots__ #559

@ccutrer

Description

@ccutrer

Given this file:

class Marker(object):
  __slots__ = ("__hash__",)

  def __init__(self):
    self.__hash__ = lambda: hash("key")

  def __eq__(self, other):
    return True

hash(Marker())

The result when running with GraalPy 3.12.8 (Oracle GraalVM Native 25.0.1):

$ bin/graalpy test.py 
Traceback (most recent call last):
  File "/home/cody/graalvm/graalpy-25.0.1-linux-amd64/test.py", line 10, in <module>
    hash(Marker())
  File "/home/cody/graalvm/graalpy-25.0.1-linux-amd64/test.py", line 5, in __init__
    self.__hash__ = lambda: hash("key")
AttributeError: 'Marker' object has no attribute '__hash__'
$ 

But running under CPython Python 3.12.3 runs just fine (no output, as expected):

$ python3 test.py
$ 

It also works just fine under GraalPy 3.11.7 (Oracle GraalVM Native 24.2.2), so this is a regression with Graal 25:

$ bin/graalpy test.py
$ 

Of note, this is a distilled test case from voluptuous. The full class is at https://github.com/alecthomas/voluptuous/blob/master/voluptuous/schema_builder.py#L948

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions