From 348bbc81ca32ccee17203dd4958e18641cbf3c3f Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 24 Sep 2019 12:53:23 -0300 Subject: [PATCH] fix for new pylint in lbry/ --- lbry/lbry/blob_exchange/client.py | 2 -- lbry/lbry/extras/cli.py | 4 ++-- lbry/lbry/extras/daemon/migrator/dbmigrator.py | 2 +- lbry/lbry/extras/daemon/migrator/migrate5to6.py | 5 ++--- lbry/lbry/extras/daemon/storage.py | 3 +-- lbry/lbry/extras/system_info.py | 2 +- lbry/lbry/wallet/server/db/reader.py | 3 ++- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lbry/lbry/blob_exchange/client.py b/lbry/lbry/blob_exchange/client.py index f69decb0c..fefe75836 100644 --- a/lbry/lbry/blob_exchange/client.py +++ b/lbry/lbry/blob_exchange/client.py @@ -83,8 +83,6 @@ class BlobExchangeClientProtocol(asyncio.Protocol): if len(data) > (self.blob.get_length() - self._blob_bytes_received): data = data[:(self.blob.get_length() - self._blob_bytes_received)] log.warning("got more than asked from %s:%d, probable sendfile bug", self.peer_address, self.peer_port) - else: - data = data self._blob_bytes_received += len(data) try: self.writer.write(data) diff --git a/lbry/lbry/extras/cli.py b/lbry/lbry/extras/cli.py index 13a28cc6a..a4862e5c1 100644 --- a/lbry/lbry/extras/cli.py +++ b/lbry/lbry/extras/cli.py @@ -65,10 +65,10 @@ def remove_brackets(key): def set_kwargs(parsed_args): kwargs = {} for key, arg in parsed_args.items(): - k = None if arg is None: continue - elif key.startswith("--") and remove_brackets(key[2:]) not in kwargs: + k = None + if key.startswith("--") and remove_brackets(key[2:]) not in kwargs: k = remove_brackets(key[2:]) elif remove_brackets(key) not in kwargs: k = remove_brackets(key) diff --git a/lbry/lbry/extras/daemon/migrator/dbmigrator.py b/lbry/lbry/extras/daemon/migrator/dbmigrator.py index 6f542448e..859dcb5d8 100644 --- a/lbry/lbry/extras/daemon/migrator/dbmigrator.py +++ b/lbry/lbry/extras/daemon/migrator/dbmigrator.py @@ -1,4 +1,5 @@ import os +import sys import logging log = logging.getLogger(__name__) @@ -51,7 +52,6 @@ def migrate_db(conf, start, end): def run_migration_script(): - import sys log_format = "(%(asctime)s)[%(filename)s:%(lineno)s] %(funcName)s(): %(message)s" logging.basicConfig(level=logging.DEBUG, format=log_format, filename="migrator.log") sys.stdout = open("migrator.out.log", 'w') diff --git a/lbry/lbry/extras/daemon/migrator/migrate5to6.py b/lbry/lbry/extras/daemon/migrator/migrate5to6.py index add03801e..49ab2ba62 100644 --- a/lbry/lbry/extras/daemon/migrator/migrate5to6.py +++ b/lbry/lbry/extras/daemon/migrator/migrate5to6.py @@ -125,10 +125,9 @@ def do_migration(conf): name_metadata_cursor.execute("select txid, n, sd_hash from name_metadata").fetchall() } - sd_hash_to_stream_hash = { - sd_hash: stream_hash for (sd_hash, stream_hash) in + sd_hash_to_stream_hash = dict( lbryfile_cursor.execute("select sd_blob_hash, stream_hash from lbry_file_descriptors").fetchall() - } + ) stream_hash_to_stream_blobs = {} diff --git a/lbry/lbry/extras/daemon/storage.py b/lbry/lbry/extras/daemon/storage.py index 2b0bf96d7..ededa684f 100644 --- a/lbry/lbry/extras/daemon/storage.py +++ b/lbry/lbry/extras/daemon/storage.py @@ -475,8 +475,7 @@ class SQLiteStorage(SQLiteMixin): os.path.join(binascii.unhexlify(download_directory).decode(), binascii.unhexlify(file_name).decode())): continue - else: - removed.append((stream_hash,)) + removed.append((stream_hash,)) if removed: transaction.executemany( "update file set file_name=null, download_directory=null, saved_file=0 where stream_hash=?", diff --git a/lbry/lbry/extras/system_info.py b/lbry/lbry/extras/system_info.py index 81810c1b3..9b36cde17 100644 --- a/lbry/lbry/extras/system_info.py +++ b/lbry/lbry/extras/system_info.py @@ -23,7 +23,7 @@ def get_platform() -> dict: "build": build_type.BUILD, # CI server sets this during build step } if p["os_system"] == "Linux": - import distro + import distro # pylint: disable=import-outside-toplevel p["distro"] = distro.info() p["desktop"] = os.environ.get('XDG_CURRENT_DESKTOP', 'Unknown') diff --git a/lbry/lbry/wallet/server/db/reader.py b/lbry/lbry/wallet/server/db/reader.py index b352d232e..89b444b2b 100644 --- a/lbry/lbry/wallet/server/db/reader.py +++ b/lbry/lbry/wallet/server/db/reader.py @@ -2,6 +2,7 @@ import time import struct import sqlite3 import logging +from operator import itemgetter from typing import Tuple, List, Dict, Union, Type, Optional from binascii import unhexlify from decimal import Decimal @@ -336,7 +337,7 @@ def search(constraints) -> Tuple[List, List, int, int]: if 'order_by' not in constraints: constraints['order_by'] = ["claim_hash"] txo_rows = _search(**constraints) - channel_hashes = set(txo['channel_hash'] for txo in txo_rows if txo['channel_hash']) + channel_hashes = set(filter(None, map(itemgetter('channel_hash'), txo_rows))) extra_txo_rows = [] if channel_hashes: extra_txo_rows = _search(