From bb75480ad98c70a7cae1d45cd3f4eb504a2da39e Mon Sep 17 00:00:00 2001 From: fselmo Date: Wed, 28 Jun 2023 11:00:31 -0600 Subject: [PATCH] Extend and more properly define typing for BlockIdentifier - Borrowing from the typing used in web3.py, where it has worked quite well, ``BlockIdentifer`` needed some modernizing that would be nice to use across libraries. eth-tester could benefit once type hinting is introduced there. --- eth_typing/evm.py | 7 ++++++- newsfragments/47.feature.rst | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 newsfragments/47.feature.rst diff --git a/eth_typing/evm.py b/eth_typing/evm.py index 7965a3e..75200e0 100644 --- a/eth_typing/evm.py +++ b/eth_typing/evm.py @@ -4,13 +4,18 @@ Union, ) +from typing_extensions import ( + Literal, +) + from .encoding import ( HexStr, ) Hash32 = NewType("Hash32", bytes) BlockNumber = NewType("BlockNumber", int) -BlockIdentifier = Union[BlockNumber, Hash32] +BlockParams = Literal["latest", "earliest", "pending", "safe", "finalized"] +BlockIdentifier = Union[BlockParams, BlockNumber, Hash32, HexStr, int] Address = NewType("Address", bytes) HexAddress = NewType("HexAddress", HexStr) diff --git a/newsfragments/47.feature.rst b/newsfragments/47.feature.rst new file mode 100644 index 0000000..6763d9f --- /dev/null +++ b/newsfragments/47.feature.rst @@ -0,0 +1 @@ +Borrowing from the typing in web3.py, open up ``BlockIdentifier`` to include ``BlockParams`` (e.g. "latest", "finalized", etc..) as well as other valid values.