Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type hints in more _utils. #1529

Merged
merged 4 commits into from Dec 2, 2019
Merged

Conversation

@njgheorghita
Copy link
Contributor

njgheorghita commented Nov 27, 2019

What was wrong?

Type hints added to:

  • web3._utils.datatypes
  • web3._utils.decorators
  • web3._utils.empty
  • web3._utils.ens
  • web3._utils.filters

Removed combomethod from web3._utils.decorators in favor of eth_utils.combomethod

Cute Animal Picture

image

@njgheorghita njgheorghita force-pushed the njgheorghita:type-hints-utils-b branch 2 times, most recently from 2472e2e to b45d82e Nov 27, 2019
@njgheorghita

This comment has been minimized.

Copy link
Contributor Author

njgheorghita commented Nov 27, 2019

@pipermerriam @kclowes I'm noticing some duplication b/w web3 & eth-utils. In this pr I deleted combomethod from web3._utils.decorators in favor of eth_utils.combomethod. I'm also noticing some duplication between web3._utils.encoding and eth-utils (i.e. a lot of the to_hex, to_int, etc..). Are those safe to remove as well in favor of the eth-utils versions? Or should all of these be deprecated instead and removed in the next major bump?

@njgheorghita njgheorghita force-pushed the njgheorghita:type-hints-utils-b branch from b45d82e to 01c124a Nov 27, 2019
@njgheorghita njgheorghita changed the title Type hints utils b Type hints in more _utils. Nov 27, 2019
@njgheorghita njgheorghita requested review from pipermerriam and kclowes Nov 27, 2019
def __init__(
cls,
name: str,
bases: Tuple[type],

This comment has been minimized.

Copy link
@pipermerriam

pipermerriam Nov 27, 2019

Member

This means a length-1 tuple with a single type. I think you probably mean: Tuple[Type[Any], ...] which may-or-may-not be equivalent to Tuple[type, ...]

"""
Decorate a deprecated function, with info about what to use instead, like:
@deprecated_for("toBytes()")
def toAscii(arg):
...
"""
def decorator(to_wrap):
def decorator(to_wrap: Callable[..., Any]) -> Callable[..., Any]:

This comment has been minimized.

Copy link
@pipermerriam

pipermerriam Nov 27, 2019

Member

Generally best to do:

TFunc = TypeVar("TFunc", bound=Callable[..., Any])

def decorator(to_wrap: TFunc) -> TFunc:
    @functools.wraps(to_wrap)
    def inner(...):
        ...
    return cast(TFunc, inner)

This preserves the types for the wrapped function.

@njgheorghita njgheorghita force-pushed the njgheorghita:type-hints-utils-b branch from b6d8057 to da3807e Dec 2, 2019
@njgheorghita njgheorghita merged commit d883ad0 into ethereum:master Dec 2, 2019
42 checks passed
42 checks passed
ci/circleci: docs Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: py36-core Your tests passed on CircleCI!
Details
ci/circleci: py36-ens Your tests passed on CircleCI!
Details
ci/circleci: py36-ethpm Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-ethtester-pyevm Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-http-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-http-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ipc-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ipc-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ws-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-goethereum-ws-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-http Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-ipc Your tests passed on CircleCI!
Details
ci/circleci: py36-integration-parity-ws Your tests passed on CircleCI!
Details
ci/circleci: py37-core Your tests passed on CircleCI!
Details
ci/circleci: py37-ens Your tests passed on CircleCI!
Details
ci/circleci: py37-ethpm Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-ethtester-pyevm Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-http-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-http-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ipc-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ipc-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ws-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-goethereum-ws-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-parity-http Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-parity-ipc Your tests passed on CircleCI!
Details
ci/circleci: py37-integration-parity-ws Your tests passed on CircleCI!
Details
ci/circleci: py38-core Your tests passed on CircleCI!
Details
ci/circleci: py38-ens Your tests passed on CircleCI!
Details
ci/circleci: py38-ethpm Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-ethtester-pyevm Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-http-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-http-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-ipc-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-ipc-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-ws-1.7.2 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-goethereum-ws-1.8.22 Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-parity-http Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-parity-ipc Your tests passed on CircleCI!
Details
ci/circleci: py38-integration-parity-ws Your tests passed on CircleCI!
Details
continuous-documentation/read-the-docs Read the Docs build succeeded!
Details
@njgheorghita njgheorghita deleted the njgheorghita:type-hints-utils-b branch Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.