comparison test/memorydb.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 e9fb7c539a52
children d0fd8bb64c3f
comparison
equal deleted inserted replaced
5394:c26d88ec071e 5395:23b8e6067f7c
132 raise KeyError(infoid) 132 raise KeyError(infoid)
133 return self[infoid] 133 return self[infoid]
134 def set(self, infoid, **newvalues): 134 def set(self, infoid, **newvalues):
135 self[infoid].update(newvalues) 135 self[infoid].update(newvalues)
136 def list(self): 136 def list(self):
137 return self.keys() 137 return list(self.keys())
138 def destroy(self, infoid): 138 def destroy(self, infoid):
139 del self[infoid] 139 del self[infoid]
140 def commit(self): 140 def commit(self):
141 pass 141 pass
142 def close(self): 142 def close(self):
288 self.security.addPermission(name="View", klass=cn, 288 self.security.addPermission(name="View", klass=cn,
289 description="User is allowed to access "+cn) 289 description="User is allowed to access "+cn)
290 290
291 def getclasses(self): 291 def getclasses(self):
292 """Return a list of the names of all existing classes.""" 292 """Return a list of the names of all existing classes."""
293 l = self.classes.keys() 293 return sorted(self.classes.keys())
294 l.sort()
295 return l
296 294
297 def getclass(self, classname): 295 def getclass(self, classname):
298 """Get the Class object representing a particular class. 296 """Get the Class object representing a particular class.
299 297
300 If 'classname' is not a valid class name, a KeyError is raised. 298 If 'classname' is not a valid class name, a KeyError is raised.

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