Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using six.iteritems to achieve iterators. We can use dict.items instead, as it will return iterators in PY3 as well. And dict.items/keys will more readable. 2.In py2, the performance about list should be negligible, see the link [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: If76115f706e9e100a1780471af0f9c5d92d3bc9f
This commit is contained in:
parent
2af0348d26
commit
3ef34da36c
@ -92,7 +92,7 @@ class ModelBase(six.Iterator):
|
||||
|
||||
def update(self, values):
|
||||
"""Make the model object behave like a dict."""
|
||||
for k, v in six.iteritems(values):
|
||||
for k, v in values.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
def _as_dict(self):
|
||||
@ -101,14 +101,14 @@ class ModelBase(six.Iterator):
|
||||
Includes attributes from joins.
|
||||
"""
|
||||
local = dict((key, value) for key, value in self)
|
||||
joined = dict([(k, v) for k, v in six.iteritems(self.__dict__)
|
||||
joined = dict([(k, v) for k, v in self.__dict__.items()
|
||||
if not k[0] == '_'])
|
||||
local.update(joined)
|
||||
return local
|
||||
|
||||
def iteritems(self):
|
||||
"""Make the model object behave like a dict."""
|
||||
return six.iteritems(self._as_dict())
|
||||
return self._as_dict().items()
|
||||
|
||||
def items(self):
|
||||
"""Make the model object behave like a dict."""
|
||||
|
@ -18,7 +18,6 @@ import mock
|
||||
from oslo_utils import uuidutils
|
||||
from oslotest import base as test_base
|
||||
from oslotest import moxstubout
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
import sqlalchemy
|
||||
from sqlalchemy.dialects import mysql
|
||||
@ -614,7 +613,7 @@ class TestMigrationUtils(db_test_base.DbTestCase):
|
||||
}
|
||||
|
||||
index_instances = [Index(name, *columns)
|
||||
for name, columns in six.iteritems(indexes)]
|
||||
for name, columns in indexes.items()]
|
||||
|
||||
table = Table(table_name, self.meta,
|
||||
Column('id', Integer, primary_key=True),
|
||||
|
Loading…
x
Reference in New Issue
Block a user