Skip to content

Commit

Permalink
Consolidate types into web3._utils.compat
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Dec 10, 2019
1 parent ea2f3b8 commit 2462afe
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@
"ipfshttpclient>=0.4.12,<1",
"jsonschema>=3.0.0,<4.0.0",
"lru-dict>=1.1.6,<2.0.0",
# remove mypy_extensions after python_requires>=3.8
# see web3._utils.compat
"mypy_extensions>=0.4.1,<1.0.0",
"protobuf>=3.10.0,<4",
"pypiwin32>=223;platform_system=='Windows'",
"requests>=2.16.0,<3.0.0",
"websockets>=8.1.0,<9.0.0",
# remove mypy_extensions & typing-extensions after python_requires>=3.8
# see web3._utils.compat
"typing-extensions>=3.7.4.1,<4",
],
setup_requires=['setuptools-markdown'],
Expand Down
3 changes: 1 addition & 2 deletions web3/_utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
Tuple,
)

from typing_extensions import (
from web3._utils.compat import (
Protocol,
)

from web3._utils.rpc_abi import (
RPC,
)
Expand Down
5 changes: 2 additions & 3 deletions web3/_utils/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# remove once web3 supports python>=3.8
# TypedDict was added to typing in 3.8
try:
from typing import Literal, TypedDict # type: ignore
from typing import Literal, Protocol, TypedDict # type: ignore
except ImportError:
from mypy_extensions import TypedDict # noqa: F401
from typing_extensions import Literal # noqa: F401
from typing_extensions import Literal, Protocol, TypedDict # type: ignore # noqa: F401
4 changes: 2 additions & 2 deletions web3/_utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import (
Any,
Callable,
Collection,
Dict,
Iterable,
Sequence,
Tuple,
TypeVar,
)
Expand Down Expand Up @@ -56,7 +56,7 @@ def apply_formatters_to_args(*formatters: Callable[[TValue], TReturn]) -> Callab
@curry
@to_list
def apply_formatter_to_array(
formatter: Callable[[TValue], TReturn], value: Collection[TValue]
formatter: Callable[[TValue], TReturn], value: Sequence[TValue]
) -> Iterable[TReturn]:
for item in value:
yield formatter(item)
Expand Down
11 changes: 4 additions & 7 deletions web3/_utils/personal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand All @@ -15,6 +14,9 @@
HexBytes,
)

from web3._utils.compat import (
Protocol,
)
from web3._utils.rpc_abi import (
RPC,
)
Expand All @@ -26,11 +28,6 @@
TxParams,
)

if TYPE_CHECKING:
from typing_extensions import ( # noqa: F401
Protocol,
)

importRawKey: Method[Callable[[str, str], ChecksumAddress]] = Method(
RPC.personal_importRawKey,
mungers=[default_root_munger],
Expand Down Expand Up @@ -61,7 +58,7 @@
)


class UnlockAccountWrapper("Protocol"):
class UnlockAccountWrapper(Protocol):
def __call__(self, account: ChecksumAddress, passphrase: str, duration: int=None) -> bool:
pass

Expand Down
2 changes: 1 addition & 1 deletion web3/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
is_string,
to_checksum_address,
)
from mypy_extensions import (
from typing_extensions import (
TypedDict,
)

Expand Down

0 comments on commit 2462afe

Please sign in to comment.