From a983bb2ec74269a30bad2f985650ef2efcda6e58 Mon Sep 17 00:00:00 2001 From: fselmo Date: Thu, 23 Feb 2023 09:03:25 -0700 Subject: [PATCH] Change ``eth_call`` return type to reflect pythonic formatter conversion - Pythonic result formatters convert ``eth_call`` response to ``HexBytes``. Due to differences between the ``HexBytes.hex()`` method and the ``bytes.hex()`` method, the former more accurately represents the type that is returned. --- newsfragments/2842.bugfix.rst | 1 + web3/eth/async_eth.py | 6 +++--- web3/eth/eth.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 newsfragments/2842.bugfix.rst diff --git a/newsfragments/2842.bugfix.rst b/newsfragments/2842.bugfix.rst new file mode 100644 index 0000000000..610ff20bb9 --- /dev/null +++ b/newsfragments/2842.bugfix.rst @@ -0,0 +1 @@ +More accurately define the ``eth_call`` return type as ``HexBytes`` since the response is converted to ``HexBytes`` in the pythonic formatters and there are differences between ``HexBytes`` and ``bytes`` types. diff --git a/web3/eth/async_eth.py b/web3/eth/async_eth.py index 307bd7aac7..09929f409e 100644 --- a/web3/eth/async_eth.py +++ b/web3/eth/async_eth.py @@ -225,7 +225,7 @@ async def fee_history( Optional[BlockIdentifier], Optional[CallOverride], ], - Awaitable[Union[bytes, bytearray]], + Awaitable[HexBytes], ] ] = Method(RPC.eth_call, mungers=[BaseEth.call_munger]) @@ -235,7 +235,7 @@ async def call( block_identifier: Optional[BlockIdentifier] = None, state_override: Optional[CallOverride] = None, ccip_read_enabled: Optional[bool] = None, - ) -> Union[bytes, bytearray]: + ) -> HexBytes: ccip_read_enabled_on_provider = self.w3.provider.global_ccip_read_enabled if ( # default conditions: @@ -255,7 +255,7 @@ async def _durin_call( transaction: TxParams, block_identifier: Optional[BlockIdentifier] = None, state_override: Optional[CallOverride] = None, - ) -> Union[bytes, bytearray]: + ) -> HexBytes: max_redirects = self.w3.provider.ccip_read_max_redirects if not max_redirects or max_redirects < 4: diff --git a/web3/eth/eth.py b/web3/eth/eth.py index c62967bc80..a1c43f8469 100644 --- a/web3/eth/eth.py +++ b/web3/eth/eth.py @@ -234,7 +234,7 @@ def fee_history( _call: Method[ Callable[ [TxParams, Optional[BlockIdentifier], Optional[CallOverride]], - Union[bytes, bytearray], + HexBytes, ] ] = Method(RPC.eth_call, mungers=[BaseEth.call_munger]) @@ -244,7 +244,7 @@ def call( block_identifier: Optional[BlockIdentifier] = None, state_override: Optional[CallOverride] = None, ccip_read_enabled: Optional[bool] = None, - ) -> Union[bytes, bytearray]: + ) -> HexBytes: ccip_read_enabled_on_provider = self.w3.provider.global_ccip_read_enabled if ( # default conditions: @@ -264,7 +264,7 @@ def _durin_call( transaction: TxParams, block_identifier: Optional[BlockIdentifier] = None, state_override: Optional[CallOverride] = None, - ) -> Union[bytes, bytearray]: + ) -> HexBytes: max_redirects = self.w3.provider.ccip_read_max_redirects if not max_redirects or max_redirects < 4: