From 0a2eff6a20fe6e4838048a19bbafe40884a70335 Mon Sep 17 00:00:00 2001 From: gecong1973 Date: Mon, 28 Nov 2016 10:43:14 +0800 Subject: [PATCH] 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 --- automaton/machines.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automaton/machines.py b/automaton/machines.py index 469d84e..7d04571 100644 --- a/automaton/machines.py +++ b/automaton/machines.py @@ -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='.'):