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: Id4355f3f96c830e3116ef6f6e0a17d2ed0dcd1f4
This commit is contained in:
gecong1973 2016-11-28 10:43:14 +08:00
parent 3c9251ccf8
commit 0a2eff6a20
1 changed files with 4 additions and 4 deletions

View File

@ -153,7 +153,7 @@ class FiniteMachine(object):
on_exit=state.on_exit)
for state in state_space:
if state.next_states:
for event, next_state in six.iteritems(state.next_states):
for event, next_state in state.next_states.items():
if isinstance(next_state, State):
next_state = next_state.name
m.add_transition(state.name, next_state, event)
@ -367,11 +367,11 @@ class FiniteMachine(object):
else:
c.frozen = self.frozen
if not shallow:
for state, data in six.iteritems(self._states):
for state, data in self._states.items():
copied_data = data.copy()
copied_data['reactions'] = copied_data['reactions'].copy()
c._states[state] = copied_data
for state, data in six.iteritems(self._transitions):
for state, data in self._transitions.items():
c._transitions[state] = data.copy()
else:
c._transitions = self._transitions
@ -402,7 +402,7 @@ class FiniteMachine(object):
def __iter__(self):
"""Iterates over (start, event, end) transition tuples."""
for state in six.iterkeys(self._states):
for event, target in six.iteritems(self._transitions[state]):
for event, target in self._transitions[state].items():
yield (state, event, target.name)
def pformat(self, sort=True, empty='.'):