Skip to content

Commit d15bbad

Browse files
lihaijingamotoki
andcommitted
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 Co-Authored-By: Akihiro Motoki <amotoki@gmail.com> Change-Id: I4b9edb326444264c0f6c4ad281acaac356a07e85 Implements: blueprint replace-iteritems-with-items
1 parent 4b57508 commit d15bbad

76 files changed

Lines changed: 148 additions & 222 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

HACKING.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ OpenStackClient strives to be Python 3.3 compatible. Common guidelines:
9393

9494
* Convert print statements to functions: print statements should be converted
9595
to an appropriate log or other output mechanism.
96-
* Use six where applicable: x.iteritems is converted to six.iteritems(x)
97-
for example.
96+
* Prefer to x.items() over six.iteritems(x).
9897

9998
Running Tests
10099
-------------

openstackclient/api/object_store_v1.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import sys
2020

2121
from osc_lib import utils
22-
import six
2322
from six.moves import urllib
2423

2524
from openstackclient.api import api
@@ -559,7 +558,7 @@ def _set_properties(self, properties, header_tag):
559558
log = logging.getLogger(__name__ + '._set_properties')
560559

561560
headers = {}
562-
for k, v in six.iteritems(properties):
561+
for k, v in properties.items():
563562
if not utils.is_ascii(k) or not utils.is_ascii(v):
564563
log.error('Cannot set property %s to non-ascii value', k)
565564
continue
@@ -572,7 +571,7 @@ def _get_properties(self, headers, header_tag):
572571
# Add in properties as a top level key, this is consistent with other
573572
# OSC commands
574573
properties = {}
575-
for k, v in six.iteritems(headers):
574+
for k, v in headers.items():
576575
if k.lower().startswith(header_tag):
577576
properties[k[len(header_tag):]] = v
578577
return properties

openstackclient/common/availability_zone.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from novaclient import exceptions as nova_exceptions
2020
from osc_lib.command import command
2121
from osc_lib import utils
22-
import six
2322

2423
from openstackclient.i18n import _
2524

@@ -47,11 +46,11 @@ def _xform_compute_availability_zone(az, include_extra):
4746
return result
4847

4948
if hasattr(az, 'hosts') and az.hosts:
50-
for host, services in six.iteritems(az.hosts):
49+
for host, services in az.hosts.items():
5150
host_info = copy.deepcopy(zone_info)
5251
host_info['host_name'] = host
5352

54-
for svc, state in six.iteritems(services):
53+
for svc, state in services.items():
5554
info = copy.deepcopy(host_info)
5655
info['service_name'] = svc
5756
info['service_status'] = '%s %s %s' % (

openstackclient/common/configuration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from keystoneauth1.loading import base
1717
from osc_lib.command import command
18-
import six
1918

2019
from openstackclient.i18n import _
2120

@@ -59,9 +58,9 @@ def take_action(self, parsed_args):
5958
if o.secret
6059
]
6160

62-
for key, value in six.iteritems(info.pop('auth', {})):
61+
for key, value in info.pop('auth', {}).items():
6362
if parsed_args.mask and key.lower() in secret_opts:
6463
value = REDACTED
6564
info['auth.' + key] = value
6665

67-
return zip(*sorted(six.iteritems(info)))
66+
return zip(*sorted(info.items()))

openstackclient/common/module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from osc_lib.command import command
2121
from osc_lib import utils
22-
import six
2322

2423
from openstackclient.i18n import _
2524

@@ -113,4 +112,4 @@ def take_action(self, parsed_args):
113112
# Catch all exceptions, just skip it
114113
pass
115114

116-
return zip(*sorted(six.iteritems(data)))
115+
return zip(*sorted(data.items()))

openstackclient/common/quota.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from osc_lib.command import command
2323
from osc_lib import utils
24-
import six
2524

2625
from openstackclient.i18n import _
2726
from openstackclient.network import common
@@ -663,4 +662,4 @@ def take_action(self, parsed_args):
663662
project_name = project_info['name']
664663
info['project_name'] = project_name
665664

666-
return zip(*sorted(six.iteritems(info)))
665+
return zip(*sorted(info.items()))

openstackclient/compute/v2/agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from osc_lib.command import command
2121
from osc_lib import exceptions
2222
from osc_lib import utils
23-
import six
2423

2524
from openstackclient.i18n import _
2625

@@ -77,7 +76,7 @@ def take_action(self, parsed_args):
7776
parsed_args.hypervisor
7877
)
7978
agent = compute_client.agents.create(*args)._info.copy()
80-
return zip(*sorted(six.iteritems(agent)))
79+
return zip(*sorted(agent.items()))
8180

8281

8382
class DeleteAgent(command.Command):

openstackclient/compute/v2/aggregate.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from osc_lib.command import command
2424
from osc_lib import exceptions
2525
from osc_lib import utils
26-
import six
2726

2827
from openstackclient.i18n import _
2928

@@ -68,7 +67,7 @@ def take_action(self, parsed_args):
6867
'properties': format_columns.DictColumn(info.pop('metadata')),
6968
},
7069
)
71-
return zip(*sorted(six.iteritems(info)))
70+
return zip(*sorted(info.items()))
7271

7372

7473
class CreateAggregate(command.ShowOne):
@@ -125,7 +124,7 @@ def take_action(self, parsed_args):
125124
'properties': properties,
126125
},
127126
)
128-
return zip(*sorted(six.iteritems(info)))
127+
return zip(*sorted(info.items()))
129128

130129

131130
class DeleteAggregate(command.Command):
@@ -255,7 +254,7 @@ def take_action(self, parsed_args):
255254
'properties': format_columns.DictColumn(info.pop('metadata')),
256255
},
257256
)
258-
return zip(*sorted(six.iteritems(info)))
257+
return zip(*sorted(info.items()))
259258

260259

261260
class SetAggregate(command.Command):
@@ -372,7 +371,7 @@ def take_action(self, parsed_args):
372371

373372
info = {}
374373
info.update(data._info)
375-
return zip(*sorted(six.iteritems(info)))
374+
return zip(*sorted(info.items()))
376375

377376

378377
class UnsetAggregate(command.Command):

openstackclient/compute/v2/console.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from osc_lib.cli import parseractions
1919
from osc_lib.command import command
2020
from osc_lib import utils
21-
import six
2221

2322
from openstackclient.i18n import _
2423

@@ -138,4 +137,4 @@ def take_action(self, parsed_args):
138137
# handle for different microversion API.
139138
console_data = data.get('remote_console', data.get('console'))
140139
info.update(console_data)
141-
return zip(*sorted(six.iteritems(info)))
140+
return zip(*sorted(info.items()))

openstackclient/compute/v2/flavor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from osc_lib.command import command
2323
from osc_lib import exceptions
2424
from osc_lib import utils
25-
import six
2625

2726
from openstackclient.i18n import _
2827
from openstackclient.identity import common as identity_common
@@ -195,7 +194,7 @@ def take_action(self, parsed_args):
195194
flavor_info.pop("links")
196195
flavor_info['properties'] = utils.format_dict(flavor.get_keys())
197196

198-
return zip(*sorted(six.iteritems(flavor_info)))
197+
return zip(*sorted(flavor_info.items()))
199198

200199

201200
class DeleteFlavor(command.Command):
@@ -447,7 +446,7 @@ def take_action(self, parsed_args):
447446

448447
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
449448

450-
return zip(*sorted(six.iteritems(flavor)))
449+
return zip(*sorted(flavor.items()))
451450

452451

453452
class UnsetFlavor(command.Command):

0 commit comments

Comments
 (0)