From 7556e31bd4f95ba48fa9d5adaff86486c775b42b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Feb 20 2020 11:43:03 +0000 Subject: Fix redundant type changes. Most of these accept iterables, so there's no need to make them into a list first. --- diff --git a/mdapi-get_repo_md b/mdapi-get_repo_md index 4641a47..8036e85 100755 --- a/mdapi-get_repo_md +++ b/mdapi-get_repo_md @@ -213,15 +213,13 @@ def compare_dbs(name, db1, db2, cache1, cache2): query = queries.get(table, default_query).format(table=table) for i, row in enumerate(conn.execute(query)): if table in cache_dependant_tables: - row = list(row) # lists support item assignment if row[0] in cache: - row[0] = cache[row[0]] - yield tuple(row) + yield (cache[row[0]], *row[1:]) else: print(f"{name.ljust(padding)} ! {row[0]!r} does not appear in the " f"{table!r} cache for {uri}. Dropping from comparison.") else: - yield tuple(row) + yield row conn.close() def build_cache(uri, cache): @@ -278,10 +276,10 @@ def compare_dbs(name, db1, db2, cache1, cache2): if table in cache_producing_tables: build_cache(db1, cache1) build_cache(db2, cache2) - rows1 = set(list(get_all_rows(db1, table, cache1))) - rows2 = set(list(get_all_rows(db2, table, cache2))) + rows1 = set(get_all_rows(db1, table, cache1)) + rows2 = set(get_all_rows(db2, table, cache2)) changed = rows1.symmetric_difference(rows2) - results.update(set([row_to_package(row) for row in changed])) + results.update({row_to_package(row) for row in changed}) return results diff --git a/mdapi/__init__.py b/mdapi/__init__.py index d9c811e..980c348 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -152,9 +152,7 @@ async def _expand_pkg_info(pkgs, branch, repotype=None): if pkg.rpm_sourcerpm: async with db.execute(GET_CO_PACKAGE, (pkg.rpm_sourcerpm,)) as cursor: copkgs = await cursor.fetchall() - out['co-packages'] = list(set([ - cpkg[2] for cpkg in copkgs - ])) + out['co-packages'] = list({cpkg[2] for cpkg in copkgs}) else: out['co-packages'] = [] out['repo'] = repotype if repotype else 'release' diff --git a/mdapi/views.py b/mdapi/views.py index 042b931..2a24db1 100644 --- a/mdapi/views.py +++ b/mdapi/views.py @@ -64,13 +64,13 @@ async def list_branches(request): ''' Return the list of all branches currently supported by mdapi ''' _log.info(f'list_branches: {request}') - output = sorted(list(set([ + output = sorted({ # Remove the front part `mdapi-` and the end part -.sqlite filename.replace('mdapi-', '').rsplit('-', 2)[0].replace( '-updates', '') for filename in os.listdir(CONFIG['DB_FOLDER']) if filename.startswith('mdapi') and filename.endswith('.sqlite') - ]))) + }) return web.json_response(output)