From a47e02cd5d93ee33394001cebf023d44bcfc3d65 Mon Sep 17 00:00:00 2001 From: Cyril Jouve Date: Fri, 28 Aug 2020 18:35:32 +0200 Subject: [PATCH 2/7] Wraps filter() usage in a list call. --- .../databases/schemas/sequences/__init__.py | 8 +++----- .../schemas/tables/tests/test_tables_acl_sql.py | 4 +--- web/pgadmin/tools/debugger/__init__.py | 2 +- .../tools/schema_diff/directory_compare.py | 15 ++++++--------- web/pgadmin/utils/sqlautocomplete/autocomplete.py | 4 ++-- web/regression/python_test_utils/test_utils.py | 4 +--- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py index b7f34a29e..e2cf25123 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/__init__.py @@ -252,11 +252,9 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare): for row in nodes: system_seq = self._get_dependency(row['oid'], show_system_objects=True) - seq = filter(lambda dep: dep['type'] == 'column' and - dep['field'] == 'internal', system_seq) - if type(seq) is not list: - seq = list(seq) - if len(seq) > 0: + seq = [dep for dep in system_seq + if dep['type'] == 'column' and dep['field'] == 'internal'] + if not seq: continue # Append the node into the newly created list diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_tables_acl_sql.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_tables_acl_sql.py index fbea605cf..372a41633 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_tables_acl_sql.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_tables_acl_sql.py @@ -41,9 +41,7 @@ class TestTablesAclSql(SQLTemplateTestBase): return sql def assertions(self, fetch_result, descriptions): - public_acls = list( - filter(lambda acl: acl[1] == 'PUBLIC', fetch_result) - ) + public_acls = [acl for acl in fetch_result if acl[1] == 'PUBLIC'] self.assertEqual(len(public_acls), 1) new_acl_map = dict( diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index b07a4de98..5130ff022 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -1269,7 +1269,7 @@ def messages(trans_id): # From the above message we need to find out port number # as "7" so below logic will find 7 as port number # and attach listened to that port number - tmp_list = list(filter(lambda x: 'PLDBGBREAK' in x, notify)) + tmp_list = [x for x in notify if 'PLDBGBREAK' in x] if len(tmp_list) > 0: port_number = re.search(r'\d+', tmp_list[0]) if port_number is not None: diff --git a/web/pgadmin/tools/schema_diff/directory_compare.py b/web/pgadmin/tools/schema_diff/directory_compare.py index ee143c319..59432755b 100644 --- a/web/pgadmin/tools/schema_diff/directory_compare.py +++ b/web/pgadmin/tools/schema_diff/directory_compare.py @@ -524,11 +524,10 @@ def directory_diff(source_dict, target_dict, ignore_keys=[], difference=None): ignore_keys, difference) elif type(source_dict[key]) is list: tmp_target = None - tmp_list = list(filter( - lambda x: type(x) == list or type(x) == dict, source_dict[key] - )) + tmp_list = [x for x in source_dict[key] + if isinstance(x, (list, dict))] - if len(tmp_list) > 0: + if tmp_list: tmp_target = copy.deepcopy(target_dict[key]) for index in range(len(source_dict[key])): source = copy.deepcopy(source_dict[key][index]) @@ -563,11 +562,9 @@ def directory_diff(source_dict, target_dict, ignore_keys=[], difference=None): # If no element in source dict then check for the element # is available in target and the type is of list. # Added such elements as a deleted. - tmp_tar_list = list(filter( - lambda x: type(x) == list or type(x) == dict, - target_dict[key] - )) - if len(tmp_tar_list): + tmp_tar_list = [x for x in target_dict[key] + if isinstance(x, (list, dict))] + if tmp_tar_list: difference[key] = {'deleted': target_dict[key]} if type(source) is dict and tmp_target and key in tmp_target and \ diff --git a/web/pgadmin/utils/sqlautocomplete/autocomplete.py b/web/pgadmin/utils/sqlautocomplete/autocomplete.py index 42b5d6b27..1031330aa 100644 --- a/web/pgadmin/utils/sqlautocomplete/autocomplete.py +++ b/web/pgadmin/utils/sqlautocomplete/autocomplete.py @@ -572,7 +572,7 @@ class SQLAutoComplete(object): lastword = last_word(word_before_cursor, include='most_punctuations') if lastword == '*': if suggestion.context == 'insert': - def filter(col): + def is_scoped(col): if not col.has_default: return True return not any( @@ -580,7 +580,7 @@ class SQLAutoComplete(object): for p in self.insert_col_skip_patterns ) scoped_cols = \ - dict((t, [col for col in cols if filter(col)]) + dict((t, [col for col in cols if is_scoped(col)]) for t, cols in scoped_cols.items()) if self.asterisk_column_order == 'alphabetic': for cols in scoped_cols.values(): diff --git a/web/regression/python_test_utils/test_utils.py b/web/regression/python_test_utils/test_utils.py index 82bce5029..7311f3cdc 100644 --- a/web/regression/python_test_utils/test_utils.py +++ b/web/regression/python_test_utils/test_utils.py @@ -1406,9 +1406,7 @@ def get_parallel_sequential_module_list(module_list): parallel_tests.remove(module) # list of tests can be executed in sequentially - sequential_tests = list( - filter(lambda i: i not in parallel_tests, - module_list)) + sequential_tests = [i for i in module_list if i not in parallel_tests] # return parallel & sequential lists return parallel_tests, sequential_tests -- 2.28.0