Skip to content

Contract event overloading breaks hasattr #1560

Closed
@Arachnid

Description

@Arachnid
  • Version: 5.0.0a6
  • Python: 3.7
  • OS: linux

What was wrong?

Calling hasattr on a contract events object should return True or False as appropriate. Instead, it raises the following exception:

Traceback (most recent call last):
  File "tools/get_names.py", line 101, in <module>
    main(parser.parse_args())
  File "tools/get_names.py", line 89, in main
    if hasattr(registrar.events, 'BidRevealed'):
  File "/home/user/.local/lib/python3.7/site-packages/web3/contract.py", line 200, in __getattr__
    "Are you sure you provided the correct contract abi?"
web3.exceptions.MismatchedABI: ("The event 'BidRevealed' was not found in this contract's abi. ", 'Are you sure you provided the correct contract abi?')

How can it be fixed?

Fix the 'helpful' overloading of __getattr__ to raise the exception expected by Python (preferable), or implement __hasattr__.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions