Skip to content

Ruby allows Arrays to be used as Hash key, Python doesn't #10

@vmedea

Description

@vmedea

I ran into an error while reading ruby data:

Traceback (most recent call last):
  File "….py", line 5, in <module>
    d = rubymarshal.reader.load(f)
  File "…/.local/lib/python3.8/site-packages/rubymarshal/reader.py", line 289, in load
    return loader.read()
  File "…/.local/lib/python3.8/site-packages/rubymarshal/reader.py", line 197, in read
    attributes = self.read_attributes()
  File "…/.local/lib/python3.8/site-packages/rubymarshal/reader.py", line 233, in read_attributes
    attr_value = self.read()
  File "…/.local/lib/python3.8/site-packages/rubymarshal/reader.py", line 125, in read
    result[key] = value
TypeError: unhashable type: 'list'

Ruby doesn't (IIRC) have a different concept of tuples and arrays. I hacked around it by adding

                if isinstance(key, list): # Workaround for non-hashable lists used as key
                    key = tuple(key)

to the reading code for TYPE_HASH. It's a bit ad-hoc but I'm not sure what a consistent fix would be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions