diff --git a/eth_pydantic_types/address.py b/eth_pydantic_types/address.py index 01cde7c..a8af9c6 100644 --- a/eth_pydantic_types/address.py +++ b/eth_pydantic_types/address.py @@ -1,13 +1,12 @@ from functools import cached_property -from typing import TYPE_CHECKING, Annotated, Any, ClassVar, Optional +from typing import Annotated, Any, ClassVar, Optional +from cchecksum import to_checksum_address +from eth_typing import ChecksumAddress from pydantic_core.core_schema import ValidationInfo, str_schema from eth_pydantic_types.hash import HashStr20 -if TYPE_CHECKING: - from eth_typing import ChecksumAddress - ADDRESS_PATTERN = "^0x[a-fA-F0-9]{40}$" @@ -35,22 +34,13 @@ def __eth_pydantic_validate__(cls, value: Any, info: Optional[ValidationInfo] = return cls.to_checksum_address(value) @classmethod - def to_checksum_address(cls, value: str) -> "ChecksumAddress": - # perf: eth_utils imports are too slow. Hence they are localized. - from eth_utils import is_checksum_address, to_checksum_address - - if is_checksum_address(value): - return value # type: ignore[return-value] - - else: - return to_checksum_address(value) + def to_checksum_address(cls, value: str) -> ChecksumAddress: + return to_checksum_address(value) class _AddressTypeFactory: @cached_property def address_type(self): - from eth_typing import ChecksumAddress - # Lazy define for performance reasons. AddressType = Annotated[ChecksumAddress, Address] AddressType.__doc__ = """ diff --git a/setup.py b/setup.py index b277740..533b2ff 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ url="https://github.com/ApeWorX/eth-pydantic-types", include_package_data=True, install_requires=[ + "cchecksum>=0.0.3,<1", "hexbytes>=0.3.1,<2", "eth-utils>=2.3.1,<6", "eth-typing>=3.5.2,<6",