Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vmedea opened this issue Sep 6, 2021 · 3 comments
Open

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

vmedea opened this issue Sep 6, 2021 · 3 comments

Comments

@vmedea
Copy link

vmedea commented Sep 6, 2021

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.

@Lost-MSth
Copy link

Lost-MSth commented Mar 27, 2023

Not enough. There maybe some nested lists. I use recursive method to solve it.

Well, I am not sure too.

@vmedea
Copy link
Author

vmedea commented May 10, 2023

Good point, it would need a recursive solution.

@d9pouces
Copy link
Owner

Can I have a test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants