Skip to content

Commit a9f1553

Browse files
committed
Fix wrong type hints
1 parent 7c5c234 commit a9f1553

File tree

28 files changed

+92
-63
lines changed

28 files changed

+92
-63
lines changed

eth/beacon/types/attestation_records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import (
22
Iterable,
3+
Tuple,
34
)
45

56
from eth_typing import (
@@ -49,7 +50,7 @@ def __init__(self,
4950
attester_bitfield: bytes,
5051
justified_slot: int,
5152
justified_block_hash: Hash32,
52-
oblique_parent_hashes: Hash32=None,
53+
oblique_parent_hashes: Tuple[Hash32, ...]=None,
5354
aggregate_sig: Iterable[int]=None) -> None:
5455
if oblique_parent_hashes is None:
5556
oblique_parent_hashes = ()

eth/chains/tester/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class BaseMainnetTesterChain(Chain):
134134
vm_configuration = _generate_vm_configuration() # type: Tuple[Tuple[int, Type[BaseVM]], ...]
135135

136136

137-
class MainnetTesterChain(BaseMainnetTesterChain): # type: ignore
137+
class MainnetTesterChain(BaseMainnetTesterChain):
138138
"""
139139
This class is intended to be used for in-memory test chains. It
140140
explicitely bypasses the proof of work validation to allow for instant

eth/db/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def _log_pending_accounts(self) -> None:
418418
accounts_displayed = set() # type: Set[bytes]
419419
queued_changes = self._journaltrie.journal.journal_data.items()
420420
# mypy bug for ordered dict reversibility: https://github.com/python/typeshed/issues/2078
421-
for checkpoint, accounts in reversed(queued_changes): # type: ignore
421+
for checkpoint, accounts in reversed(queued_changes):
422422
for address in accounts:
423423
if address in accounts_displayed:
424424
continue

eth/db/chain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_block_uncles(self, uncles_hash: Hash32) -> List[BlockHeader]:
9494
@abstractmethod
9595
def persist_block(self,
9696
block: 'BaseBlock'
97-
) -> Tuple[Tuple[bytes, ...], Tuple[bytes, ...]]:
97+
) -> Tuple[Tuple[Hash32, ...], Tuple[Hash32, ...]]:
9898
raise NotImplementedError("ChainDB classes must implement this method")
9999

100100
@abstractmethod
@@ -223,7 +223,7 @@ def _set_as_canonical_chain_head(cls,
223223
#
224224
def persist_block(self,
225225
block: 'BaseBlock'
226-
) -> Tuple[Tuple[bytes, ...], Tuple[bytes, ...]]:
226+
) -> Tuple[Tuple[Hash32, ...], Tuple[Hash32, ...]]:
227227
'''
228228
Persist the given block's header and uncles.
229229
@@ -236,7 +236,7 @@ def persist_block(self,
236236
def _persist_block(
237237
cls,
238238
db: 'BaseDB',
239-
block: 'BaseBlock') -> Tuple[Tuple[bytes, ...], Tuple[bytes, ...]]:
239+
block: 'BaseBlock') -> Tuple[Tuple[Hash32, ...], Tuple[Hash32, ...]]:
240240
header_chain = (block.header, )
241241
new_canonical_headers, old_canonical_headers = cls._persist_header_chain(db, header_chain)
242242

eth/db/journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __getitem__(self, key: bytes) -> Union[bytes, DeletedEntry]:
127127
order, returning from the first one in which the key is present.
128128
"""
129129
# Ignored from mypy because of https://github.com/python/typeshed/issues/2078
130-
for changeset_data in reversed(self.journal_data.values()): # type: ignore
130+
for changeset_data in reversed(self.journal_data.values()):
131131
if key in changeset_data:
132132
return changeset_data[key]
133133
else:

eth/utils/blake.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from eth_typing import Hash32
2+
13
# This module only supports for Python3.6+, ignore the type hints test for now.
24
from hashlib import blake2b # type: ignore
35

46

5-
def blake(data: bytes) -> bytes:
6-
return blake2b(data).digest()[:32]
7+
def blake(data: bytes) -> Hash32:
8+
return Hash32(blake2b(data).digest()[:32])

eth/utils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def construct_evm_runtime_identifier():
1414
platform=sys.platform,
1515
v=sys.version_info,
1616
# mypy Doesn't recognize the `sys` module as having an `implementation` attribute.
17-
imp=sys.implementation, # type: ignore
17+
imp=sys.implementation,
1818
)

eth/vm/computation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class BaseComputation(Configurable, ABC):
115115

116116
# VM configuration
117117
opcodes = None # type: Dict[int, Opcode]
118-
_precompiles = None # type: Dict[bytes, Callable[['BaseComputation'], Any]]
118+
_precompiles = None # type: Dict[Address, Callable[['BaseComputation'], Any]]
119119

120120
logger = cast(TraceLogger, logging.getLogger('eth.vm.computation.Computation'))
121121

@@ -566,7 +566,7 @@ def apply_computation(cls,
566566
# Opcode API
567567
#
568568
@property
569-
def precompiles(self) -> Dict[bytes, Callable[['BaseComputation'], Any]]:
569+
def precompiles(self) -> Dict[Address, Callable[['BaseComputation'], Any]]:
570570
if self._precompiles is None:
571571
return dict()
572572
else:

p2p/discovery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def process(response: List[kademlia.Node]) -> None:
289289
return tuple(n for n in neighbours if n != self.this_node)
290290

291291
def _mkpingid(self, token: Hash32, node: kademlia.Node) -> Hash32:
292-
return token + node.pubkey.to_bytes()
292+
return Hash32(token + node.pubkey.to_bytes())
293293

294294
def _send_find_node(self, node: kademlia.Node, target_node_id: int) -> None:
295295
if self.use_v5:
@@ -492,7 +492,7 @@ def send_ping_v4(self, node: kademlia.Node) -> Hash32:
492492
message = _pack_v4(CMD_PING.id, payload, self.privkey)
493493
self.send(node, message)
494494
# Return the msg hash, which is used as a token to identify pongs.
495-
token = message[:MAC_SIZE]
495+
token = Hash32(message[:MAC_SIZE])
496496
self.logger.trace('>>> ping (v4) %s (token == %s)', node, encode_hex(token))
497497
# XXX: This hack is needed because there are lots of parity 1.10 nodes out there that send
498498
# the wrong token on pong msgs (https://github.com/paritytech/parity/issues/8038). We
@@ -680,7 +680,7 @@ def recv_topic_register(self, node: kademlia.Node, payload: Tuple[Any, ...],
680680
topic_idx = big_endian_to_int(idx)
681681
self.logger.trace(
682682
'<<< topic_register from %s, topics: %s, idx: %d', node, topics, topic_idx)
683-
_, _, pong_payload, _ = _unpack_v5(raw_pong)
683+
key, cmd_id, pong_payload, _ = _unpack_v5(raw_pong)
684684
_, _, _, _, ticket_serial, _ = pong_payload
685685
self.topic_table.use_ticket(node, big_endian_to_int(ticket_serial), topics[topic_idx])
686686

@@ -1132,7 +1132,7 @@ def _unpack_v4(message: bytes) -> Tuple[datatypes.PublicKey, int, Tuple[Any, ...
11321132
11331133
Returns the public key used to sign the message, the cmd ID, payload and hash.
11341134
"""
1135-
message_hash = message[:MAC_SIZE]
1135+
message_hash = Hash32(message[:MAC_SIZE])
11361136
if message_hash != keccak(message[MAC_SIZE:]):
11371137
raise WrongMAC("Wrong msg mac")
11381138
signature = keys.Signature(message[MAC_SIZE:HEAD_SIZE])

scripts/peer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Union,
1515
)
1616

17+
from eth_typing import BlockNumber
1718
from eth.chains.mainnet import MainnetChain, MAINNET_GENESIS_HEADER, MAINNET_VM_CONFIGURATION
1819
from eth.chains.ropsten import RopstenChain, ROPSTEN_GENESIS_HEADER, ROPSTEN_VM_CONFIGURATION
1920
from eth.db.backends.memory import MemoryDB
@@ -83,7 +84,10 @@ async def request_stuff() -> None:
8384
peer_pool.logger.info("Waiting for peer connection...")
8485
await asyncio.sleep(0.2)
8586
peer = peer_pool.highest_td_peer
86-
headers = await cast(ETHPeer, peer).requests.get_block_headers(2440319, max_headers=100)
87+
headers = await cast(ETHPeer, peer).requests.get_block_headers(
88+
BlockNumber(2440319),
89+
max_headers=100
90+
)
8791
hashes = tuple(header.hash for header in headers)
8892
if peer_class == ETHPeer:
8993
peer = cast(ETHPeer, peer)

0 commit comments

Comments
 (0)