pylint and mypy fixes

This commit is contained in:
Lex Berezhny 2018-08-16 00:56:46 -04:00
parent 133a86cd89
commit df251def26
6 changed files with 16 additions and 16 deletions

View file

@ -27,4 +27,5 @@ disable=
too-many-arguments,
too-many-public-methods,
too-many-instance-attributes,
protected-access
protected-access,
unused-argument

View file

@ -27,7 +27,7 @@ class BaseHeaders:
chunk_size: int
max_target: int
genesis_hash: bytes
genesis_hash: Optional[bytes]
target_timespan: int
validate_difficulty: bool = True
@ -36,7 +36,7 @@ class BaseHeaders:
if path == ':memory:':
self.io = BytesIO()
self.path = path
self._size = None
self._size: Optional[int] = None
self._on_change_controller = StreamController()
self.on_changed = self._on_change_controller.stream
self._header_connect_lock = defer.DeferredLock()
@ -61,7 +61,8 @@ class BaseHeaders:
def get_next_chunk_target(self, chunk: int) -> ArithUint256:
return ArithUint256(self.max_target)
def get_next_block_target(self, chunk_target: ArithUint256, previous: Optional[dict],
@staticmethod
def get_next_block_target(chunk_target: ArithUint256, previous: Optional[dict],
current: Optional[dict]) -> ArithUint256:
return chunk_target

View file

@ -11,7 +11,7 @@ from torba import baseaccount
from torba import basenetwork
from torba import basetransaction
from torba.basedatabase import BaseDatabase
from torba.baseheader import BaseHeaders, InvalidHeader
from torba.baseheader import BaseHeaders
from torba.coinselection import CoinSelector
from torba.constants import COIN, NULL_HASH32
from torba.stream import StreamController

View file

@ -8,8 +8,8 @@ __electrumx__ = 'electrumx.lib.coins.BitcoinCashRegtest'
from binascii import unhexlify
from torba.baseledger import BaseLedger
from torba.baseheader import BaseHeaders
from torba.basetransaction import BaseTransaction
from .bitcoinsegwit import MainHeaders, UnverifiedHeaders
class Transaction(BaseTransaction):
@ -23,6 +23,7 @@ class MainNetLedger(BaseLedger):
symbol = 'BCH'
network_name = 'mainnet'
headers_class = MainHeaders
transaction_class = Transaction
pubkey_address_prefix = bytes((0,))
@ -33,10 +34,6 @@ class MainNetLedger(BaseLedger):
default_fee_per_byte = 50
class UnverifiedHeaders(BaseHeaders):
verify_bits_to_target = False
class RegTestLedger(MainNetLedger):
headers_class = UnverifiedHeaders
network_name = 'regtest'

View file

@ -7,6 +7,7 @@ __node_url__ = (
__electrumx__ = 'electrumx.lib.coins.BitcoinSegwitRegtest'
import struct
from typing import Optional
from binascii import hexlify, unhexlify
from torba.baseledger import BaseLedger
from torba.baseheader import BaseHeaders, ArithUint256
@ -16,7 +17,7 @@ class MainHeaders(BaseHeaders):
header_size = 80
chunk_size = 2016
max_target = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
genesis_hash = b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
genesis_hash: Optional[bytes] = b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
target_timespan = 14 * 24 * 60 * 60
@staticmethod

View file

@ -1,5 +1,5 @@
from binascii import unhexlify, hexlify
from typing import TypeVar, Sequence
from typing import TypeVar, Sequence, Optional
T = TypeVar('T')
@ -52,7 +52,7 @@ class ArithUint256:
def __init__(self, value: int) -> None:
self._value = value
self._compact = None
self._compact: Optional[int] = None
@classmethod
def from_compact(cls, compact) -> 'ArithUint256':
@ -80,10 +80,10 @@ class ArithUint256:
@property
def bits(self) -> int:
""" Returns the position of the highest bit set plus one. """
bn = bin(self._value)[2:]
for i, d in enumerate(bn):
bits = bin(self._value)[2:]
for i, d in enumerate(bits):
if d:
return (len(bn) - i) + 1
return (len(bits) - i) + 1
return 0
@property