summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuyamin <liuyamin@fiberhome.com>2017-07-19 13:58:44 +0800
committerliuyamin <liuyamin@fiberhome.com>2017-07-19 14:13:15 +0800
commit3ef34da36ccfe34ed0d2d572d2aa6b6a515b18a2 (patch)
tree32cc3db8829ad8c6f07355a4ec073e517000061f
parent2af0348d26f69e4be5c5af4989782a0c78b1aba9 (diff)
downloadoslo-db-3ef34da36ccfe34ed0d2d572d2aa6b6a515b18a2.tar.gz
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
-rw-r--r--oslo_db/sqlalchemy/models.py6
-rw-r--r--oslo_db/tests/sqlalchemy/test_utils.py3
2 files changed, 4 insertions, 5 deletions
diff --git a/oslo_db/sqlalchemy/models.py b/oslo_db/sqlalchemy/models.py
index 0467971..6fa0f6f 100644
--- a/oslo_db/sqlalchemy/models.py
+++ b/oslo_db/sqlalchemy/models.py
@@ -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."""
diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py
index 40a7ea2..932c1ea 100644
--- a/oslo_db/tests/sqlalchemy/test_utils.py
+++ b/oslo_db/tests/sqlalchemy/test_utils.py
@@ -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),