Skip to content

web3.datastructures.AttributeDict.__hash__ fails if event logs contain list objects #2908

Closed
@JustCallMeDavid

Description

@JustCallMeDavid
  • Version: 5.31.1
  • Python: 3.8
  • OS: linux
  • pip freeze output omitted since not a package specific issue

What was wrong?

Note: Not exactly an issue but something I had to circumvent myself when using the library and thinking it may be helpful if web3.py handled it instead directly.

I was trying to use functions requiring __hash__ on event logs and the code failed saying lists are not hashable here. This happens if the event logs contain list objects nested inside them (which some smart contracts seem to return), as lists by default are mutable and thus not hashable in Python.

How can it be fixed?

Would it make sense to (possibly recursively) cast any present lists to tuples inside the hash function to avoid crashes? Would some detection mechanism inside these pseudo-immutable classes be helpful to make sure they are indeed hashable (e.g., raising an error if a list is added)?

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    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