changeset 8152:95ca00cd722f stable

cleanup: minor correctness fixes "Trivial" potential problems spotted with pytype.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 03 Feb 2020 15:46:22 +0100
parents 09225e452612
children 30a1a7785c81
files kallithea/controllers/admin/repo_groups.py kallithea/controllers/pullrequests.py kallithea/lib/diffs.py kallithea/lib/utils2.py kallithea/lib/vcs/nodes.py
diffstat 5 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/controllers/admin/repo_groups.py	Mon Feb 03 15:46:22 2020 +0100
@@ -148,6 +148,7 @@
         # permissions for can create group based on parent_id are checked
         # here in the Form
         repo_group_form = RepoGroupForm(repo_groups=c.repo_groups)
+        form_result = None
         try:
             form_result = repo_group_form.to_python(dict(request.POST))
             gr = RepoGroupModel().create(
@@ -171,6 +172,8 @@
             log.error(traceback.format_exc())
             h.flash(_('Error occurred during creation of repository group %s')
                     % request.POST.get('group_name'), category='error')
+            if form_result is None:
+                raise
             parent_group_id = form_result['parent_group_id']
             # TODO: maybe we should get back to the main view, not the admin one
             raise HTTPFound(location=url('repos_groups', parent_group=parent_group_id))
--- a/kallithea/controllers/pullrequests.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/controllers/pullrequests.py	Mon Feb 03 15:46:22 2020 +0100
@@ -470,14 +470,15 @@
          c.a_rev) = c.pull_request.other_ref.split(':') # a_rev is ancestor
 
         org_scm_instance = c.cs_repo.scm_instance # property with expensive cache invalidation check!!!
-        try:
-            c.cs_ranges = []
-            for x in c.pull_request.revisions:
+        c.cs_ranges = []
+        for x in c.pull_request.revisions:
+            try:
                 c.cs_ranges.append(org_scm_instance.get_changeset(x))
-        except ChangesetDoesNotExistError:
-            c.cs_ranges = []
-            h.flash(_('Revision %s not found in %s') % (x, c.cs_repo.repo_name),
-                'error')
+            except ChangesetDoesNotExistError:
+                c.cs_ranges = []
+                h.flash(_('Revision %s not found in %s') % (x, c.cs_repo.repo_name),
+                    'error')
+                break
         c.cs_ranges_org = None # not stored and not important and moving target - could be calculated ...
         revs = [ctx.revision for ctx in reversed(c.cs_ranges)]
         c.jsdata = graph_data(org_scm_instance, revs)
--- a/kallithea/lib/diffs.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/lib/diffs.py	Mon Feb 03 15:46:22 2020 +0100
@@ -557,8 +557,8 @@
     added = deleted = 0
     old_line = old_end = new_line = new_end = None
 
+    chunks = []
     try:
-        chunks = []
         line = diff_lines.next()
 
         while True:
--- a/kallithea/lib/utils2.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/lib/utils2.py	Mon Feb 03 15:46:22 2020 +0100
@@ -374,7 +374,7 @@
     :returns: filtered list of strings
     """
     if not uri:
-        return ''
+        return []
 
     proto = ''
 
@@ -541,11 +541,11 @@
         raise HookEnvironmentError("Environment variable KALLITHEA_EXTRAS not found")
 
     extras = json.loads(kallithea_extras)
-    try:
-        for k in ['username', 'repository', 'scm', 'action', 'ip', 'config']:
+    for k in ['username', 'repository', 'scm', 'action', 'ip', 'config']:
+        try:
             extras[k]
-    except KeyError:
-        raise HookEnvironmentError('Missing key %s in KALLITHEA_EXTRAS %s' % (k, extras))
+        except KeyError:
+            raise HookEnvironmentError('Missing key %s in KALLITHEA_EXTRAS %s' % (k, extras))
 
     return AttributeDict(extras)
 
--- a/kallithea/lib/vcs/nodes.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/lib/vcs/nodes.py	Mon Feb 03 15:46:22 2020 +0100
@@ -329,8 +329,8 @@
                 encoding = None
 
                 # try with pygments
+                from pygments import lexers
                 try:
-                    from pygments import lexers
                     mt = lexers.get_lexer_for_filename(self.name).mimetypes
                 except lexers.ClassNotFound:
                     mt = None