Skip to content

Commit

Permalink
Update broken mypy types
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita authored and corydickson committed Mar 28, 2020
1 parent 063985a commit cf86df3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
9 changes: 5 additions & 4 deletions ethpm_cli/commands/activate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from argparse import Namespace
import json
from typing import Any, Dict, Iterable, Tuple
from typing import Any, Dict, Iterable, Tuple, Type
from urllib import parse

from IPython import embed
Expand Down Expand Up @@ -158,15 +158,16 @@ def activate_package(args: Namespace, config: Config) -> None:
user_ns={
**available_factories,
**available_instances,
**available_w3s,
**helper_fns,
# ignore b/c conflicting types w/in dict values
**available_w3s, # type: ignore
**helper_fns, # type: ignore
},
banner1=banner,
colors="neutral",
)


def get_factory(target_factory: Contract, target_w3: Web3) -> Contract:
def get_factory(target_factory: Contract, target_w3: Web3) -> Type[Contract]:
return target_w3.eth.contract(
abi=target_factory.abi, bytecode=target_factory.bytecode
)
Expand Down
6 changes: 4 additions & 2 deletions ethpm_cli/commands/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, Iterable, Tuple
from urllib import parse

from eth_typing import URI
from eth_typing import URI, ChecksumAddress, HexAddress, HexStr
from eth_utils import to_dict, to_hex, to_int
from ethpm.backends.base import BaseURIBackend
from ethpm.tools import builder
Expand Down Expand Up @@ -47,7 +47,9 @@ def build_etherscan_manifest(
contract_type = body["ContractName"]
w3 = setup_w3(to_int(text=chain_id))
block_uri = create_latest_block_uri(w3)
runtime_bytecode = to_hex(w3.eth.getCode(address))
runtime_bytecode = to_hex(
w3.eth.getCode(ChecksumAddress(HexAddress(HexStr(address))))
)

yield "package_name", package_name
yield "version", version
Expand Down
4 changes: 2 additions & 2 deletions ethpm_cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
import shutil
import tempfile
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple
from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple

from eth_typing import URI
from eth_utils import to_dict, to_int, to_text, to_tuple
Expand Down Expand Up @@ -232,7 +232,7 @@ def update_package(args: Namespace, config: Config) -> None:


def pluck_release_data(
all_release_data: List[str], target_version: str
all_release_data: Tuple[Tuple[str, str], ...], target_version: str
) -> Optional[URI]:
for version, uri in all_release_data:
if version == target_version:
Expand Down
6 changes: 3 additions & 3 deletions ethpm_cli/commands/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Optional, Tuple

from eth_typing import Manifest
from eth_typing import HexStr, Manifest
from eth_utils import is_checksum_address, to_hex, to_int, to_list, to_tuple
from ethpm.constants import SUPPORTED_CHAIN_IDS
from ethpm.tools import builder as b
Expand Down Expand Up @@ -350,9 +350,9 @@ def get_deployment_chain_data(w3: Web3) -> Tuple[Optional[str], Optional[Any]]:
# todo: deployment_bytecode, runtime_bytecode, compiler
flag = parse_bool_flag("Do you have a tx hash for your deployment?")
if flag:
tx_hash = input("Please enter your tx hash. ")
tx_hash = HexStr(input("Please enter your tx hash. "))
tx = w3.eth.getTransaction(tx_hash)
return tx_hash, to_hex(tx.blockHash)
return tx_hash, to_hex(tx["blockHash"])
return (None, None)


Expand Down
10 changes: 5 additions & 5 deletions ethpm_cli/commands/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from typing import Any, Dict, Iterable, List, Set, Tuple # noqa: F401

from eth_typing import URI, Address
from eth_typing import URI, Address, BlockNumber
from eth_utils import to_dict, to_list
from eth_utils.toolz import assoc
from ethpm._utils.ipfs import extract_ipfs_path_from_uri, is_ipfs_uri
Expand All @@ -25,15 +25,15 @@
BATCH_SIZE = 5000


def scrape(w3: Web3, ethpm_dir: Path, start_block: int = 0) -> int:
def scrape(w3: Web3, ethpm_dir: Path, start_block: int = 0) -> BlockNumber:
"""
Scrapes VersionRelease event data starting from start_block.
If start_block is not 0, scraping begins from start_block.
Otherwise the scraping begins from the ethpm birth block.
"""
chain_data_path = ethpm_dir / "chain_data.json"
latest_block = w3.eth.blockNumber
latest_block = BlockNumber(w3.eth.blockNumber)

if start_block >= latest_block:
raise BlockNotFoundError(
Expand All @@ -52,7 +52,7 @@ def scrape(w3: Web3, ethpm_dir: Path, start_block: int = 0) -> int:
logger.info("Scraping from block %d.", active_block)
for from_block in range(active_block, latest_block, BATCH_SIZE):
if (from_block + BATCH_SIZE) > latest_block:
to_block = latest_block
to_block = int(latest_block)
else:
to_block = from_block + BATCH_SIZE

Expand All @@ -77,7 +77,7 @@ def get_ethpm_birth_block(
version_release_date = datetime.fromtimestamp(target_timestamp)

while from_block < to_block:
mid = (from_block + to_block) // 2
mid = BlockNumber((from_block + to_block) // 2)
target = datetime.fromtimestamp(w3.eth.getBlock(mid)["timestamp"])
if target > version_release_date:
to_block = mid
Expand Down
3 changes: 2 additions & 1 deletion ethpm_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def setup_w3(chain_id: int, private_key: str = None) -> Web3:
owner_address = Account.from_key(private_key).address
signing_middleware = construct_sign_and_send_raw_middleware(private_key)
w3.middleware_onion.add(signing_middleware)
w3.eth.defaultAccount = to_checksum_address(owner_address)
# ignore b/c defaultAccount inits as Empty
w3.eth.defaultAccount = to_checksum_address(owner_address) # type: ignore
cli_logger.debug(
"In-flight tx signing has been enabled for address: {owner_address}."
)
Expand Down
3 changes: 2 additions & 1 deletion ethpm_cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Union

from eth_typing import Hash32
from eth_utils import humanize_hash
from ethpm.constants import SUPPORTED_CHAIN_IDS

Expand Down Expand Up @@ -448,7 +449,7 @@ def scrape_action(args: argparse.Namespace) -> None:
cli_logger.info("Loading IPFS scraper...")
start_block = args.start_block if args.start_block else 0
last_scraped_block = scrape(config.w3, xdg_ethpmcli_root, start_block)
last_scraped_block_hash = config.w3.eth.getBlock(last_scraped_block)["hash"]
last_scraped_block_hash = Hash32(config.w3.eth.getBlock(last_scraped_block)["hash"])
cli_logger.info(
"All blocks scraped up to # %d: %s.",
last_scraped_block,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"black>=19.3b0,<20",
"flake8>=3.7.0,<4",
"isort>=4.3.17,<5",
"mypy<0.800",
"mypy>=0.770,<0.800",
"pydocstyle>=3.0.0,<4",
],
'doc': [
Expand Down

0 comments on commit cf86df3

Please sign in to comment.