Skip to content

Commit 2c2b568

Browse files
committed
Adjust Type Hinting in other modules, Update tox.ini
1 parent 40badfe commit 2c2b568

File tree

9 files changed

+40
-32
lines changed

9 files changed

+40
-32
lines changed

eth/chains/base.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
if TYPE_CHECKING:
119119
from eth.vm.base import ( # noqa: F401
120120
BaseVM,
121-
VM,
122121
)
123122

124123

@@ -176,7 +175,7 @@ def get_vm_class(cls, header: BlockHeader) -> Type['BaseVM']:
176175
return cls.get_vm_class_for_block_number(header.block_number)
177176

178177
@abstractmethod
179-
def get_vm(self, header: BlockHeader=None) -> 'VM':
178+
def get_vm(self, header: BlockHeader=None) -> 'BaseVM':
180179
raise NotImplementedError("Chain classes must implement this method")
181180

182181
@classmethod
@@ -243,10 +242,11 @@ def get_canonical_block_hash(self, block_number: BlockNumber) -> Hash32:
243242
raise NotImplementedError("Chain classes must implement this method")
244243

245244
@abstractmethod
246-
def build_block_with_transactions(self,
247-
transactions: Tuple[BaseTransaction, ...],
248-
parent_header: BlockHeader=None
249-
) -> Tuple[BaseBlock, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]: # noqa: E501
245+
def build_block_with_transactions(
246+
self,
247+
transactions: Tuple[BaseTransaction, ...],
248+
parent_header: BlockHeader=None
249+
) -> Tuple[BaseBlock, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]:
250250
raise NotImplementedError("Chain classes must implement this method")
251251

252252
#
@@ -335,7 +335,7 @@ class Chain(BaseChain):
335335
current block number.
336336
"""
337337
logger = logging.getLogger("eth.chain.chain.Chain")
338-
gas_estimator = None # type: Callable[[BaseState, BaseTransaction], int]
338+
gas_estimator = None # type: Callable[[BaseState, BaseTransaction], int]
339339

340340
chaindb_class = ChainDB # type: Type[BaseChainDB]
341341

@@ -418,7 +418,7 @@ def from_genesis_header(cls,
418418
#
419419
# VM API
420420
#
421-
def get_vm(self, at_header: BlockHeader=None) -> 'VM':
421+
def get_vm(self, at_header: BlockHeader=None) -> 'BaseVM':
422422
"""
423423
Returns the VM instance for the given block number.
424424
"""
@@ -541,10 +541,11 @@ def get_canonical_block_hash(self, block_number: BlockNumber) -> Hash32:
541541
"""
542542
return self.chaindb.get_canonical_block_hash(block_number)
543543

544-
def build_block_with_transactions(self,
545-
transactions: Tuple[BaseTransaction, ...],
546-
parent_header: BlockHeader=None
547-
) -> Tuple[BaseBlock, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]: # noqa: E501
544+
def build_block_with_transactions(
545+
self,
546+
transactions: Tuple[BaseTransaction, ...],
547+
parent_header: BlockHeader=None
548+
) -> Tuple[BaseBlock, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]:
548549
"""
549550
Generate a block with the provided transactions. This does *not* import
550551
that block into your chain. If you want this new block in your chain,
@@ -647,7 +648,7 @@ def estimate_gas(
647648
if at_header is None:
648649
at_header = self.get_canonical_head()
649650
with self.get_vm(at_header).state_in_temp_block() as state:
650-
return self.gas_estimator(state, transaction) # type: ignore
651+
return self.gas_estimator(state, transaction) # type: ignore
651652

652653
def import_block(self,
653654
block: BaseBlock,
@@ -912,7 +913,7 @@ def mine_block(self, *args: Any, **kwargs: Any) -> BaseBlock:
912913
self.header = self.create_header_from_parent(mined_block.header)
913914
return mined_block
914915

915-
def get_vm(self, at_header: BlockHeader=None) -> 'VM':
916+
def get_vm(self, at_header: BlockHeader=None) -> 'BaseVM':
916917
if at_header is None:
917918
at_header = self.header
918919

eth/db/cache.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from lru import LRU
22

3-
from typing import Any
4-
53
from eth.db.backends.base import BaseDB
64

75

@@ -18,16 +16,16 @@ def __init__(self, db: BaseDB, cache_size: int=2048) -> None:
1816
def reset_cache(self) -> None:
1917
self._cached_values = LRU(self._cache_size)
2018

21-
def __getitem__(self, key: Any) -> Any:
19+
def __getitem__(self, key: bytes) -> bytes:
2220
if key not in self._cached_values:
2321
self._cached_values[key] = self._db[key]
2422
return self._cached_values[key]
2523

26-
def __setitem__(self, key: Any, value: Any) -> None:
24+
def __setitem__(self, key: bytes, value: bytes) -> None:
2725
self._cached_values[key] = value
2826
self._db[key] = value
2927

30-
def __delitem__(self, key: Any) -> None:
28+
def __delitem__(self, key: bytes) -> None:
3129
if key in self._cached_values:
3230
del self._cached_values[key]
3331
del self._db[key]

eth/vm/base.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ def execute_bytecode(self,
127127
code_address: Address=None) -> BaseComputation:
128128
raise NotImplementedError("VM classes must implement this method")
129129

130+
@abstractmethod
131+
def apply_all_transactions(
132+
self,
133+
transactions: Tuple[BaseTransaction, ...],
134+
base_header: BlockHeader
135+
) -> Tuple[BlockHeader, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]:
136+
raise NotImplementedError("VM classes must implement this method")
137+
130138
@abstractmethod
131139
def make_receipt(self,
132140
base_header: BlockHeader,
@@ -452,9 +460,11 @@ def execute_bytecode(self,
452460
transaction_context,
453461
)
454462

455-
def apply_all_transactions(self,
456-
transactions: Tuple[BaseTransaction, ...],
457-
base_header: BlockHeader) -> Tuple[BlockHeader, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]: # noqa: E501
463+
def apply_all_transactions(
464+
self,
465+
transactions: Tuple[BaseTransaction, ...],
466+
base_header: BlockHeader
467+
) -> Tuple[BlockHeader, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]:
458468
"""
459469
Determine the results of applying all transactions to the base header.
460470
This does *not* update the current block or header of the VM.

eth/vm/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class BaseComputation(Configurable, ABC):
116116

117117
# VM configuration
118118
opcodes = None # type: Dict[int, Any]
119-
_precompiles = None # type: Dict[Address, Callable[['BaseComputation'], Any]]
119+
_precompiles = None # type: Dict[Address, Callable[['BaseComputation'], 'BaseComputation']]
120120

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

eth/vm/forks/frontier/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FrontierComputation(BaseComputation):
4242
"""
4343
# Override
4444
opcodes = FRONTIER_OPCODES
45-
_precompiles = FRONTIER_PRECOMPILES
45+
_precompiles = FRONTIER_PRECOMPILES # type: ignore # https://github.com/python/mypy/issues/708 # noqa: E501
4646

4747
def apply_message(self) -> BaseComputation:
4848
snapshot = self.state.snapshot()

p2p/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def __repr__(self) -> str:
10841084
@to_list
10851085
def _extract_nodes_from_payload(
10861086
sender: kademlia.Address,
1087-
payload: List[Tuple[str, str, str, str]],
1087+
payload: List[Tuple[str, str, str, bytes]],
10881088
logger: TraceLogger) -> Iterator[kademlia.Node]:
10891089
for item in payload:
10901090
ip, udp_port, tcp_port, node_id = item

tox.ini

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ commands=
104104
{[common-lint]commands}
105105
flake8 {toxinidir}/tests --exclude="trinity,p2p"
106106
# TODO: Drop --ignore-missing-imports once we have type annotations for eth_utils, coincurve and cytoolz
107-
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs -p eth
108-
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth.utils
109-
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth.tools
110-
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth.vm
107+
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth
111108

112109

113110
[testenv:py36-lint]

trinity/chains/header.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Tuple, Type
88

99
from eth.db.backends.base import BaseDB
10+
from eth.db.header import BaseHeaderDB
1011
from eth.chains.header import (
1112
BaseHeaderChain,
1213
HeaderChain,
@@ -51,7 +52,7 @@ def from_genesis_header(cls,
5152
raise NotImplementedError("Chain classes must implement this method")
5253

5354
@classmethod
54-
def get_headerdb_class(cls) -> BaseDB:
55+
def get_headerdb_class(cls) -> Type[BaseHeaderDB]:
5556
raise NotImplementedError("Chain classes must implement this method")
5657

5758
coro_get_block_header_by_hash = async_method('get_block_header_by_hash')

trinity/chains/light.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ async def coro_get_canonical_block_by_number(self, block_number: BlockNumber) ->
175175
def get_canonical_block_hash(self, block_number: BlockNumber) -> Hash32:
176176
return self._headerdb.get_canonical_block_hash(block_number)
177177

178-
def build_block_with_transactions(
179-
self, transactions: Tuple[BaseTransaction, ...], parent_header: BlockHeader) -> None:
178+
def build_block_with_transactions(self,
179+
transactions: Tuple[BaseTransaction, ...],
180+
parent_header: BlockHeader=None) -> Tuple[BaseBlock, Tuple[Receipt, ...], Tuple[BaseComputation, ...]]: # noqa: E501
180181
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3])
181182

182183
#

0 commit comments

Comments
 (0)