diff roundup/cgi/templating.py @ 5395:23b8e6067f7c

Python 3 preparation: update calls to dict methods. Tool-assisted patch. Changes of iterkeys / itervalues / iteritems to keys / values / items are fully automated, but may make things less efficient in Python 2. Automated tools want to add list() around many calls to keys / values / items, but I thought most such list() additions were unnecessary because it seemed the result of keys / values / items was just iterated over while the set of dict keys remained unchanged, rather than used in a way requiring an actual list, or used while the set of keys in the dict could change. It's quite possible I missed some cases where list() was really needed, or left in some unnecessary list() calls. In cases where list() was only needed because the resulting list was then sorted in-place, I changed the code to use calls to sorted().
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 23:04:42 +0000
parents d26921b851c3
children dccae35caa59
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Tue Jul 24 23:03:35 2018 +0000
+++ b/roundup/cgi/templating.py	Tue Jul 24 23:04:42 2018 +0000
@@ -376,8 +376,7 @@
             raise AttributeError(attr)
 
     def classes(self):
-        l = self._client.db.classes.keys()
-        l.sort()
+        l = sorted(self._client.db.classes.keys())
         m = []
         for item in l:
             m.append(HTMLClass(self._client, item))
@@ -670,8 +669,7 @@
     def propnames(self):
         """ Return the list of the names of the properties of this class.
         """
-        idlessprops = self._klass.getprops(protected=0).keys()
-        idlessprops.sort()
+        idlessprops = sorted(self._klass.getprops(protected=0).keys())
         return ['id'] + idlessprops
 
     def filter(self, request=None, filterspec={}, sort=[], group=[]):
@@ -738,8 +736,7 @@
         the "property" belongs to.
         """
         if properties is None:
-            properties = self._klass.getprops(protected=0).keys()
-            properties.sort()
+            properties = sorted(self._klass.getprops(protected=0).keys())
             properties = ','.join(properties)
         if sort is None:
             if 'username' in properties.split( ',' ):

Roundup Issue Tracker: http://roundup-tracker.org/