Skip to content

Is the ContractEvent type bugged? #1646

@carver

Description

@carver

What was wrong?

When calling contract.events.Event(), mypy warns that ContractEvent is not callable.

How can it be fixed?

After digging a little deeper, it seems that these three annotations should probably be Type[ContractEvent] instead:

web3.py/web3/contract.py

Lines 246 to 263 in 92cf641

def __getattr__(self, event_name: str) -> "ContractEvent":
if '_events' not in self.__dict__:
raise NoABIEventsFound(
"The abi for this contract contains no event definitions. ",
"Are you sure you provided the correct contract abi?"
)
elif event_name not in self.__dict__['_events']:
raise ABIEventFunctionNotFound(
"The event '{}' was not found in this contract's abi. ".format(event_name),
"Are you sure you provided the correct contract abi?"
)
else:
return super().__getattribute__(event_name)
def __getitem__(self, event_name: str) -> "ContractEvent":
return getattr(self, event_name)
def __iter__(self) -> Iterable["ContractEvent"]:

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