changeset 8013:e8e9f33e9ff6

py3: use comprehensions and generators instead of filters - it is more explicit, and sometimes shorter From 2to3 -f filter.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 23 Nov 2019 22:47:35 +0100
parents ce5d4c582a82
children d2319cb2ba9b
files kallithea/controllers/admin/repo_groups.py kallithea/controllers/changeset.py kallithea/lib/caching_query.py kallithea/lib/diffs.py kallithea/lib/helpers.py kallithea/lib/utils2.py kallithea/model/repo.py kallithea/model/validators.py
diffstat 8 files changed, 12 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/controllers/admin/repo_groups.py	Sat Nov 23 22:47:35 2019 +0100
@@ -92,10 +92,8 @@
         return data
 
     def _revoke_perms_on_yourself(self, form_result):
-        _up = filter(lambda u: request.authuser.username == u[0],
-                     form_result['perms_updates'])
-        _new = filter(lambda u: request.authuser.username == u[0],
-                      form_result['perms_new'])
+        _up = [u for u in form_result['perms_updates'] if request.authuser.username == u[0]]
+        _new = [u for u in form_result['perms_new'] if request.authuser.username == u[0]]
         if _new and _new[0][1] != 'group.admin' or _up and _up[0][1] != 'group.admin':
             return True
         return False
--- a/kallithea/controllers/changeset.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/controllers/changeset.py	Sat Nov 23 22:47:35 2019 +0100
@@ -66,7 +66,7 @@
 
 def get_ignore_ws(fid, GET):
     ig_ws_global = GET.get('ignorews')
-    ig_ws = filter(lambda k: k.startswith('WS'), GET.getall(fid))
+    ig_ws = [k for k in GET.getall(fid) if k.startswith('WS')]
     if ig_ws:
         try:
             return int(ig_ws[0].split(':')[-1])
@@ -109,9 +109,9 @@
 def get_line_ctx(fid, GET):
     ln_ctx_global = GET.get('context')
     if fid:
-        ln_ctx = filter(lambda k: k.startswith('C'), GET.getall(fid))
+        ln_ctx = [k for k in GET.getall(fid) if k.startswith('C')]
     else:
-        _ln_ctx = filter(lambda k: k.startswith('C'), GET)
+        _ln_ctx = [k for k in GET if k.startswith('C')]
         ln_ctx = GET.get(_ln_ctx[0]) if _ln_ctx else ln_ctx_global
         if ln_ctx:
             ln_ctx = [ln_ctx]
--- a/kallithea/lib/caching_query.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/lib/caching_query.py	Sat Nov 23 22:47:35 2019 +0100
@@ -139,8 +139,7 @@
     if cache_key is None:
         # cache key - the value arguments from this query's parameters.
         args = [safe_str(x) for x in _params_from_query(query)]
-        args.extend(filter(lambda k: k not in ['None', None, u'None'],
-                           [str(query._limit), str(query._offset)]))
+        args.extend([k for k in [str(query._limit), str(query._offset)] if k not in ['None', None, u'None']])
 
         cache_key = " ".join(args)
 
--- a/kallithea/lib/diffs.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/lib/diffs.py	Sat Nov 23 22:47:35 2019 +0100
@@ -216,8 +216,7 @@
         stats = (0, 0)
 
     if not html_diff:
-        submodules = filter(lambda o: isinstance(o, SubModuleNode),
-                            [filenode_new, filenode_old])
+        submodules = [o for o in [filenode_new, filenode_old] if isinstance(o, SubModuleNode)]
         if submodules:
             html_diff = wrap_to_table(h.escape('Submodule %r' % submodules[0]))
         else:
@@ -235,8 +234,7 @@
     """
     # make sure we pass in default context
     context = context or 3
-    submodules = filter(lambda o: isinstance(o, SubModuleNode),
-                        [filenode_new, filenode_old])
+    submodules = [o for o in [filenode_new, filenode_old] if isinstance(o, SubModuleNode)]
     if submodules:
         return ''
 
--- a/kallithea/lib/helpers.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/lib/helpers.py	Sat Nov 23 22:47:35 2019 +0100
@@ -676,7 +676,7 @@
             return _op, _name
 
         revs = []
-        if len(filter(lambda v: v != '', revs_ids)) > 0:
+        if len([v for v in revs_ids if v != '']) > 0:
             repo = None
             for rev in revs_ids[:revs_top_limit]:
                 _op, _name = _get_op(rev)
--- a/kallithea/lib/utils2.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/lib/utils2.py	Sat Nov 23 22:47:35 2019 +0100
@@ -394,7 +394,7 @@
     else:
         host, port = uri[:cred_pos], uri[cred_pos + 1:]
 
-    return filter(None, [proto, host, port])
+    return [_f for _f in [proto, host, port] if _f]
 
 
 def credentials_filter(uri):
--- a/kallithea/model/repo.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/model/repo.py	Sat Nov 23 22:47:35 2019 +0100
@@ -306,8 +306,7 @@
                     repo=cur_repo, user='default', perm=EMPTY_PERM
                 )
                 # handle extra fields
-            for field in filter(lambda k: k.startswith(RepositoryField.PREFIX),
-                                kwargs):
+            for field in [k for k in kwargs if k.startswith(RepositoryField.PREFIX)]:
                 k = RepositoryField.un_prefix_key(field)
                 ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo)
                 if ex_field:
--- a/kallithea/model/validators.py	Sat Nov 23 23:59:28 2019 +0100
+++ b/kallithea/model/validators.py	Sat Nov 23 22:47:35 2019 +0100
@@ -782,7 +782,7 @@
 
         def _convert_to_python(self, value, state):
             # filter empty values
-            return filter(lambda s: s not in [None, ''], value)
+            return [s for s in value if s not in [None, '']]
 
         def _validate_python(self, value, state):
             from kallithea.lib import auth_modules