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

upgrade pylint and fix lint errors #3405

Merged
merged 2 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
install:
pip install -e .

tools:
pip install mypy==0.701 pylint==2.4.4
pip install coverage astroid pylint

lint:
pylint --rcfile=setup.cfg lbry
#mypy --ignore-missing-imports lbry
Expand Down
2 changes: 1 addition & 1 deletion lbry/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def contribute_to_argparse(self, parser: ArgumentParser):
)
parser.add_argument(
self.no_cli_name,
help=f"Disable maximum key fee check.",
help="Disable maximum key fee check.",
dest=self.name,
const=None,
action="store_const",
Expand Down
2 changes: 1 addition & 1 deletion lbry/dht/protocol/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def handle_error_datagram(self, address, error_datagram: ErrorDatagram):
address[0], address[1], OLD_PROTOCOL_ERRORS[error_datagram.response]
)

def datagram_received(self, datagram: bytes, address: typing.Tuple[str, int]) -> None: # pylint: disable=arguments-differ
def datagram_received(self, datagram: bytes, address: typing.Tuple[str, int]) -> None: # pylint: disable=arguments-renamed
try:
message = decode_datagram(datagram)
except (ValueError, TypeError, DecodeError):
Expand Down
2 changes: 1 addition & 1 deletion lbry/dht/protocol/routing_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_peer(self, peer: 'KademliaPeer') -> bool:
self.peers.append(peer)
return True
else:
for i in range(len(self.peers)):
for i, _ in enumerate(self.peers):
local_peer = self.peers[i]
if local_peer.node_id == peer.node_id:
self.peers.remove(local_peer)
Expand Down
6 changes: 3 additions & 3 deletions lbry/dht/serialization/datagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def decode_datagram(datagram: bytes) -> typing.Union[RequestDatagram, ResponseDa
def make_compact_ip(address: str) -> bytearray:
compact_ip = reduce(lambda buff, x: buff + bytearray([int(x)]), address.split('.'), bytearray())
if len(compact_ip) != 4:
raise ValueError(f"invalid IPv4 length")
raise ValueError("invalid IPv4 length")
return compact_ip


Expand All @@ -190,7 +190,7 @@ def make_compact_address(node_id: bytes, address: str, port: int) -> bytearray:
if not 0 < port < 65536:
raise ValueError(f'Invalid port: {port}')
if len(node_id) != constants.HASH_BITS // 8:
raise ValueError(f"invalid node node_id length")
raise ValueError("invalid node node_id length")
return compact_ip + port.to_bytes(2, 'big') + node_id


Expand All @@ -201,5 +201,5 @@ def decode_compact_address(compact_address: bytes) -> typing.Tuple[bytes, str, i
if not 0 < port < 65536:
raise ValueError(f'Invalid port: {port}')
if len(node_id) != constants.HASH_BITS // 8:
raise ValueError(f"invalid node node_id length")
raise ValueError("invalid node node_id length")
return node_id, address, port
2 changes: 1 addition & 1 deletion lbry/error/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_arguments(self):
@staticmethod
def get_fields(args):
if len(args) > 1:
return f''.join(f'\n{INDENT*2}self.{field} = {field}' for field in args[1:])
return ''.join(f'\n{INDENT*2}self.{field} = {field}' for field in args[1:])
return ''

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion lbry/extras/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, *args, group_name=None, **kwargs):
self._optionals.title = 'Options'
if group_name is None:
self.epilog = (
f"Run 'lbrynet COMMAND --help' for more information on a command or group."
"Run 'lbrynet COMMAND --help' for more information on a command or group."
)
else:
self.epilog = (
Expand Down
18 changes: 9 additions & 9 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,9 +1701,9 @@ def jsonrpc_account_set(
'change': {'gap': change_gap, 'maximum_uses_per_address': change_max_uses},
'receiving': {'gap': receiving_gap, 'maximum_uses_per_address': receiving_max_uses},
}
for chain_name in address_changes:
for chain_name, changes in address_changes.items():
chain = getattr(account, chain_name)
for attr, value in address_changes[chain_name].items():
for attr, value in changes.items():
if value is not None:
setattr(chain, attr, value)
change_made = True
Expand Down Expand Up @@ -2240,15 +2240,15 @@ async def jsonrpc_purchase_create(
txo = await self.ledger.get_claim_by_claim_id(accounts, claim_id, include_purchase_receipt=True)
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find claim with claim_id '{claim_id}'. ")
raise Exception(f"Could not find claim with claim_id '{claim_id}'.")
elif url:
txo = (await self.ledger.resolve(accounts, [url], include_purchase_receipt=True))[url]
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find claim with url '{url}'. ")
raise Exception(f"Could not find claim with url '{url}'.")
else:
# TODO: use error from lbry.error
raise Exception(f"Missing argument claim_id or url. ")
raise Exception("Missing argument claim_id or url.")
if not allow_duplicate_purchase and txo.purchase_receipt:
# TODO: use error from lbry.error
raise Exception(
Expand Down Expand Up @@ -4091,15 +4091,15 @@ async def jsonrpc_collection_resolve(
txo = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find collection with claim_id '{claim_id}'. ")
raise Exception(f"Could not find collection with claim_id '{claim_id}'.")
elif url:
txo = (await self.ledger.resolve(wallet.accounts, [url]))[url]
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find collection with url '{url}'. ")
raise Exception(f"Could not find collection with url '{url}'.")
else:
# TODO: use error from lbry.error
raise Exception(f"Missing argument claim_id or url. ")
raise Exception("Missing argument claim_id or url.")

page_num, page_size = abs(page), min(abs(page_size), 50)
items = await self.ledger.resolve_collection(txo, page_size * (page_num - 1), page_size)
Expand Down Expand Up @@ -5072,7 +5072,7 @@ def jsonrpc_routing_table_get(self):
'buckets': {}
}

for i in range(len(self.dht_node.protocol.routing_table.buckets)):
for i, _ in enumerate(self.dht_node.protocol.routing_table.buckets):
result['buckets'][i] = []
for peer in self.dht_node.protocol.routing_table.buckets[i].peers:
host = {
Expand Down
2 changes: 1 addition & 1 deletion lbry/extras/daemon/json_response_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(self, *args, ledger: Ledger, include_protobuf=False, **kwargs):
self.ledger = ledger
self.include_protobuf = include_protobuf

def default(self, obj): # pylint: disable=method-hidden,arguments-differ,too-many-return-statements
def default(self, obj): # pylint: disable=method-hidden,arguments-renamed,too-many-return-statements
if isinstance(obj, Account):
return self.encode_account(obj)
if isinstance(obj, Wallet):
Expand Down
4 changes: 2 additions & 2 deletions lbry/extras/daemon/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _recover(transaction: sqlite3.Connection):
).fetchall()
download_dir = binascii.hexlify(self.conf.download_dir.encode()).decode()
transaction.executemany(
f"update file set download_directory=? where stream_hash=?",
"update file set download_directory=? where stream_hash=?",
((download_dir, stream_hash) for stream_hash in stream_hashes)
).fetchall()
await self.db.run_with_foreign_keys_disabled(_recover)
Expand Down Expand Up @@ -861,6 +861,6 @@ def _save_kademlia_peers(transaction: sqlite3.Connection):
transaction.execute('delete from peer').fetchall()
transaction.executemany(
'insert into peer(node_id, address, udp_port, tcp_port) values (?, ?, ?, ?)',
tuple([(binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers])
((binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers)
).fetchall()
return await self.db.run(_save_kademlia_peers)
4 changes: 2 additions & 2 deletions lbry/file_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ async def _verify_executables(self):
version = str(e)
if code != 0 or not version.startswith("ffmpeg"):
log.warning("Unable to run ffmpeg, but it was requested. Code: %d; Message: %s", code, version)
raise FileNotFoundError(f"Unable to locate or run ffmpeg or ffprobe. Please install FFmpeg "
f"and ensure that it is callable via PATH or conf.ffmpeg_path")
raise FileNotFoundError("Unable to locate or run ffmpeg or ffprobe. Please install FFmpeg "
"and ensure that it is callable via PATH or conf.ffmpeg_path")
log.debug("Using %s at %s", version.splitlines()[0].split(" Copyright")[0], self._which_ffmpeg)
return version

Expand Down
2 changes: 1 addition & 1 deletion lbry/stream/managed_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def _save_file(self, output_path: str):
self.finished_writing.clear()
self.started_writing.clear()
try:
open(output_path, 'wb').close()
open(output_path, 'wb').close() # pylint: disable=consider-using-with
async for blob_info, decrypted in self._aiter_read_stream(connection_id=self.SAVING_ID):
log.info("write blob %i/%i", blob_info.blob_num + 1, len(self.descriptor.blobs) - 1)
await self.loop.run_in_executor(None, self._write_decrypted_blob, output_path, decrypted)
Expand Down
6 changes: 3 additions & 3 deletions lbry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def wrapper(func):
async def _inner(*args, **kwargs) -> typing.Any:
loop = asyncio.get_running_loop()
time_now = loop.time()
key = tuple([args, tuple([tuple([k, kwargs[k]]) for k in kwargs])])
key = (args, tuple(kwargs.items()))
if key in cache and (time_now - cache[key][1] < duration):
return cache[key][0]
to_cache = await func(*args, **kwargs)
Expand All @@ -173,7 +173,7 @@ def cache_concurrent(async_fn):

@functools.wraps(async_fn)
async def wrapper(*args, **kwargs):
key = tuple([args, tuple([tuple([k, kwargs[k]]) for k in kwargs])])
key = (args, tuple(kwargs.items()))
cache[key] = cache.get(key) or asyncio.create_task(async_fn(*args, **kwargs))
try:
return await cache[key]
Expand Down Expand Up @@ -342,7 +342,7 @@ def wrapper(async_fn):

@functools.wraps(async_fn)
async def _inner(*args, **kwargs):
key = tuple([args, tuple([tuple([k, kwargs[k]]) for k in kwargs])])
key = (args, tuple(kwargs.items()))
if key in lru_cache:
return lru_cache.get(key)

Expand Down
2 changes: 1 addition & 1 deletion lbry/wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __init__(self, ledger: 'Ledger', wallet: 'Wallet', name: str,
generator_name = address_generator.get('name', HierarchicalDeterministic.name)
self.address_generator = self.address_generators[generator_name]
self.receiving, self.change = self.address_generator.from_dict(self, address_generator)
self.address_managers = {am.chain_number: am for am in {self.receiving, self.change}}
self.address_managers = {am.chain_number: am for am in (self.receiving, self.change)}
self.channel_keys = channel_keys
ledger.add_account(self)
wallet.add_account(self)
Expand Down
8 changes: 5 additions & 3 deletions lbry/wallet/bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def _extended_key(self, ver_bytes, raw_serkey):
if len(raw_serkey) != 33:
raise ValueError('raw_serkey must have length 33')

return (ver_bytes + bytes((self.depth,))
+ self.parent_fingerprint() + self.n.to_bytes(4, 'big')
+ self.chain_code + raw_serkey)
return (
ver_bytes + bytes((self.depth,))
+ self.parent_fingerprint() + self.n.to_bytes(4, 'big')
+ self.chain_code + raw_serkey
)

def identifier(self):
raise NotImplementedError
Expand Down
6 changes: 3 additions & 3 deletions lbry/wallet/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class AIOSQLite:
"read_count", "Number of database reads", namespace="daemon_database"
)
acquire_write_lock_metric = Histogram(
f'write_lock_acquired', 'Time to acquire the write lock', namespace="daemon_database", buckets=HISTOGRAM_BUCKETS
'write_lock_acquired', 'Time to acquire the write lock', namespace="daemon_database", buckets=HISTOGRAM_BUCKETS
)
held_write_lock_metric = Histogram(
f'write_lock_held', 'Length of time the write lock is held for', namespace="daemon_database",
'write_lock_held', 'Length of time the write lock is held for', namespace="daemon_database",
buckets=HISTOGRAM_BUCKETS
)

Expand Down Expand Up @@ -506,7 +506,7 @@ def _get_spendable_utxos(transaction: sqlite3.Connection, accounts: List, decode
amount_to_reserve: int, reserved_amount: int, floor: int, ceiling: int,
fee_per_byte: int) -> int:
accounts_fmt = ",".join(["?"] * len(accounts))
txo_query = f"""
txo_query = """
SELECT tx.txid, txo.txoid, tx.raw, tx.height, txo.position as nout, tx.is_verified, txo.amount FROM txo
INNER JOIN account_address USING (address)
LEFT JOIN txi USING (txoid)
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ disable=
c-extension-no-member,
fixme,
broad-except,
raise-missing-from,
no-else-return,
cyclic-import,
missing-docstring,
Expand All @@ -37,5 +38,6 @@ disable=
too-many-public-methods,
too-many-return-statements,
too-many-instance-attributes,
unspecified-encoding,
protected-access,
unused-argument
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
] + PLYVEL,
extras_require={
'torrent': ['lbry-libtorrent'],
'lint': ['mypy==0.701', 'pylint==2.4.4'],
'lint': ['pylint==2.10.0'],
'test': ['coverage'],
},
classifiers=[
Expand Down