Leverage dict comprehension in PEP-0274
PEP-0274 introduced dict comprehensions to replace dict constructor with a sqeuence of key-pairs[1], these are benefits: First, it makes the code look neater. Second, it gains a micro-optimization. We dropped python 2.6 support, we can leverage this now. Note: This commit doesn't handle dict constructor with kwargs. [1]http://legacy.python.org/dev/peps/pep-0274/ Change-Id: Ifca656d516809a6a52cf15bac3f6361e8d83aa58
This commit is contained in:
parent
ab0a66e16a
commit
b524bf5b71
oslo_versionedobjects
@ -55,7 +55,7 @@ class ConvertedException(webob.exc.WSGIHTTPException):
|
||||
|
||||
def _cleanse_dict(original):
|
||||
"""Strip all admin_password, new_pass, rescue_pass keys from a dict."""
|
||||
return dict([(k, v) for k, v in original.items() if "_pass" not in k])
|
||||
return {k: v for k, v in original.items() if "_pass" not in k}
|
||||
|
||||
|
||||
def wrap_exception(notifier=None, get_notifier=None):
|
||||
|
@ -525,16 +525,15 @@ class DictProxyField(object):
|
||||
return self
|
||||
if getattr(obj, self._fld_name) is None:
|
||||
return
|
||||
return dict([(self._key_type(k), v)
|
||||
for k, v in six.iteritems(getattr(obj, self._fld_name))])
|
||||
return {self._key_type(k): v
|
||||
for k, v in six.iteritems(getattr(obj, self._fld_name))}
|
||||
|
||||
def __set__(self, obj, val):
|
||||
if val is None:
|
||||
setattr(obj, self._fld_name, val)
|
||||
else:
|
||||
setattr(obj, self._fld_name,
|
||||
dict([(six.text_type(k), v)
|
||||
for k, v in six.iteritems(val)]))
|
||||
{six.text_type(k): v for k, v in six.iteritems(val)})
|
||||
|
||||
|
||||
class Set(CompoundFieldType):
|
||||
|
Loading…
x
Reference in New Issue
Block a user