Remove six.iteritems usage

We also remove hacking tests for this, along with those for iterkeys and
itervalues (no usage of these).

Change-Id: If5b46580078eb756651ac6118f502eccdc693646
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2021-12-21 11:42:17 +00:00
parent 0562e3335b
commit 502fa0ffc8
15 changed files with 21 additions and 87 deletions

View File

@ -20,6 +20,3 @@ glance Specific Commandments
- [G328] Must use a dict comprehension instead of a dict constructor with - [G328] Must use a dict comprehension instead of a dict constructor with
a sequence of key-value pairs a sequence of key-value pairs
- [G329] Python 3: Do not use xrange. - [G329] Python 3: Do not use xrange.
- [G330] Python 3: do not use dict.iteritems.
- [G331] Python 3: do not use dict.iterkeys.
- [G332] Python 3: do not use dict.itervalues.

View File

@ -417,7 +417,7 @@ class BaseClient(object):
to_str = str to_str = str
else: else:
to_str = encodeutils.safe_encode to_str = encodeutils.safe_encode
return {to_str(h): to_str(v) for h, v in six.iteritems(headers)} return {to_str(h): to_str(v) for h, v in headers.items()}
@handle_redirects @handle_redirects
def _do_request(self, method, url, body, headers): def _do_request(self, method, url, body, headers):

View File

@ -16,7 +16,6 @@
"""Storage preference based location strategy module""" """Storage preference based location strategy module"""
from oslo_config import cfg from oslo_config import cfg
import six
import six.moves.urllib.parse as urlparse import six.moves.urllib.parse as urlparse
from glance.i18n import _ from glance.i18n import _
@ -116,7 +115,7 @@ def get_ordered_locations(locations, uri_key='url', **kwargs):
pieces = urlparse.urlparse(uri.strip()) pieces = urlparse.urlparse(uri.strip())
store_name = None store_name = None
for store, schemes in six.iteritems(_STORE_TO_SCHEME_MAP): for store, schemes in _STORE_TO_SCHEME_MAP.items():
if pieces.scheme.strip() in schemes: if pieces.scheme.strip() in schemes:
store_name = store store_name = store
break break

View File

@ -384,10 +384,9 @@ def create_mashup_dict(image_meta):
""" """
d = {} d = {}
for key, value in six.iteritems(image_meta): for key, value in image_meta.items():
if isinstance(value, dict): if isinstance(value, dict):
for subkey, subvalue in six.iteritems( for subkey, subvalue in create_mashup_dict(value).items():
create_mashup_dict(value)):
if subkey not in image_meta: if subkey not in image_meta:
d[subkey] = subvalue d[subkey] = subvalue
else: else:
@ -522,7 +521,7 @@ def no_4byte_params(f):
def _check_dict(data_dict): def _check_dict(data_dict):
# a dict of dicts has to be checked recursively # a dict of dicts has to be checked recursively
for key, value in six.iteritems(data_dict): for key, value in data_dict.items():
if isinstance(value, dict): if isinstance(value, dict):
_check_dict(value) _check_dict(value)
else: else:

View File

@ -947,7 +947,7 @@ class Debug(Middleware):
resp = req.get_response(self.application) resp = req.get_response(self.application)
print(("*" * 40) + " RESPONSE HEADERS") print(("*" * 40) + " RESPONSE HEADERS")
for (key, value) in six.iteritems(resp.headers): for key, value in resp.headers.items():
print(key, "=", value) print(key, "=", value)
print('') print('')

View File

@ -20,7 +20,6 @@ import uuid
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import six
from glance.common import exception from glance.common import exception
from glance.common import timeutils from glance.common import timeutils
@ -312,7 +311,7 @@ def _filter_images(images, filters, context,
continue continue
to_add = True to_add = True
for k, value in six.iteritems(filters): for k, value in filters.items():
key = k key = k
if k.endswith('_min') or k.endswith('_max'): if k.endswith('_min') or k.endswith('_max'):
key = key[0:-4] key = key[0:-4]
@ -1092,7 +1091,7 @@ def _filter_tasks(tasks, filters, context, admin_as_user=False):
continue continue
add = True add = True
for k, value in six.iteritems(filters): for k, value in filters.items():
add = task[k] == value and task['deleted'] is False add = task[k] == value and task['deleted'] is False
if not add: if not add:
break break

View File

@ -1175,7 +1175,7 @@ def _set_properties_for_image(context, image_ref, properties,
for prop_ref in image_ref.properties: for prop_ref in image_ref.properties:
orig_properties[prop_ref.name] = prop_ref orig_properties[prop_ref.name] = prop_ref
for name, value in six.iteritems(properties): for name, value in properties.items():
prop_values = {'image_id': image_ref.id, prop_values = {'image_id': image_ref.id,
'name': name, 'name': name,
'value': value} 'value': value}

View File

@ -26,7 +26,6 @@ import re
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import encodeutils from oslo_utils import encodeutils
import six
import sqlalchemy import sqlalchemy
from sqlalchemy import and_ from sqlalchemy import and_
from sqlalchemy.schema import MetaData from sqlalchemy.schema import MetaData
@ -309,15 +308,15 @@ def _populate_metadata(meta, metadata_path=None, merge=False,
_update_rt_association(namespace_rt_table, values, _update_rt_association(namespace_rt_table, values,
rt_id, namespace_id) rt_id, namespace_id)
for property, schema in six.iteritems(metadata.get('properties', for name, schema in metadata.get('properties', {}).items():
{})):
values = { values = {
'name': property, 'name': name,
'namespace_id': namespace_id, 'namespace_id': namespace_id,
'json_schema': json.dumps(schema) 'json_schema': json.dumps(schema)
} }
property_id = _get_resource_id(properties_table, property_id = _get_resource_id(
namespace_id, property) properties_table, namespace_id, name,
)
if not property_id: if not property_id:
values.update({'created_at': timeutils.utcnow()}) values.update({'created_at': timeutils.utcnow()})
_insert_data_to_db(properties_table, values) _insert_data_to_db(properties_table, values)

View File

@ -131,27 +131,3 @@ def check_python3_xrange(logical_line):
if re.search(r"\bxrange\s*\(", logical_line): if re.search(r"\bxrange\s*\(", logical_line):
yield(0, "G329: Do not use xrange. Use range, or six.moves.range for " yield(0, "G329: Do not use xrange. Use range, or six.moves.range for "
"large loops.") "large loops.")
@core.flake8ext
def check_python3_no_iteritems(logical_line):
msg = ("G330: Use six.iteritems() or dict.items() instead of "
"dict.iteritems().")
if re.search(r".*\.iteritems\(\)", logical_line):
yield(0, msg)
@core.flake8ext
def check_python3_no_iterkeys(logical_line):
msg = ("G331: Use six.iterkeys() or dict.keys() instead of "
"dict.iterkeys().")
if re.search(r".*\.iterkeys\(\)", logical_line):
yield(0, msg)
@core.flake8ext
def check_python3_no_itervalues(logical_line):
msg = ("G332: Use six.itervalues() or dict.values instead of "
"dict.itervalues().")
if re.search(r".*\.itervalues\(\)", logical_line):
yield(0, msg)

View File

@ -22,7 +22,6 @@ from oslo_log import log as logging
import oslo_messaging import oslo_messaging
from oslo_utils import encodeutils from oslo_utils import encodeutils
from oslo_utils import excutils from oslo_utils import excutils
import six
import webob import webob
from glance.common import exception from glance.common import exception
@ -219,7 +218,7 @@ def format_metadef_namespace_notification(metadef_namespace):
def format_metadef_object_notification(metadef_object): def format_metadef_object_notification(metadef_object):
object_properties = metadef_object.properties or {} object_properties = metadef_object.properties or {}
properties = [] properties = []
for name, prop in six.iteritems(object_properties): for name, prop in object_properties.items():
object_property = _format_metadef_object_property(name, prop) object_property = _format_metadef_object_property(name, prop)
properties.append(object_property) properties.append(object_property)

View File

@ -15,7 +15,6 @@
import jsonschema import jsonschema
from oslo_utils import encodeutils from oslo_utils import encodeutils
import six
from glance.common import exception from glance.common import exception
from glance.i18n import _ from glance.i18n import _
@ -42,7 +41,7 @@ class Schema(object):
def filter(self, obj): def filter(self, obj):
filtered = {} filtered = {}
for key, value in six.iteritems(obj): for key, value in obj.items():
if self._filter_func(self.properties, key): if self._filter_func(self.properties, key):
filtered[key] = value filtered[key] = value

View File

@ -1516,7 +1516,7 @@ class TestImages(functional.FunctionalTest):
'min_ram': 0, 'min_ram': 0,
'schema': '/v2/schemas/image', 'schema': '/v2/schemas/image',
} }
for key, value in six.iteritems(expected_image): for key, value in expected_image.items():
self.assertEqual(value, image[key], key) self.assertEqual(value, image[key], key)
# Upload data to image # Upload data to image
@ -1586,7 +1586,7 @@ class TestImages(functional.FunctionalTest):
'schema': '/v2/schemas/image', 'schema': '/v2/schemas/image',
} }
for key, value in six.iteritems(expected_image): for key, value in expected_image.items():
self.assertEqual(value, image[key], key) self.assertEqual(value, image[key], key)
# Upload data to image # Upload data to image
@ -1658,7 +1658,7 @@ class TestImages(functional.FunctionalTest):
'schema': '/v2/schemas/image', 'schema': '/v2/schemas/image',
} }
for key, value in six.iteritems(expected_image): for key, value in expected_image.items():
self.assertEqual(value, image[key], key) self.assertEqual(value, image[key], key)
# Upload data to image # Upload data to image

View File

@ -108,33 +108,3 @@ class HackingTestCase(utils.BaseTestCase):
self.assertEqual(0, len(list(func('for i in range(10)')))) self.assertEqual(0, len(list(func('for i in range(10)'))))
self.assertEqual(0, len(list(func('for i in six.moves.range(10)')))) self.assertEqual(0, len(list(func('for i in six.moves.range(10)'))))
self.assertEqual(0, len(list(func('testxrange(10)')))) self.assertEqual(0, len(list(func('testxrange(10)'))))
def test_dict_iteritems(self):
self.assertEqual(1, len(list(checks.check_python3_no_iteritems(
"obj.iteritems()"))))
self.assertEqual(0, len(list(checks.check_python3_no_iteritems(
"six.iteritems(obj)"))))
self.assertEqual(0, len(list(checks.check_python3_no_iteritems(
"obj.items()"))))
def test_dict_iterkeys(self):
self.assertEqual(1, len(list(checks.check_python3_no_iterkeys(
"obj.iterkeys()"))))
self.assertEqual(0, len(list(checks.check_python3_no_iterkeys(
"six.iterkeys(obj)"))))
self.assertEqual(0, len(list(checks.check_python3_no_iterkeys(
"obj.keys()"))))
def test_dict_itervalues(self):
self.assertEqual(1, len(list(checks.check_python3_no_itervalues(
"obj.itervalues()"))))
self.assertEqual(0, len(list(checks.check_python3_no_itervalues(
"six.itervalues(ob)"))))
self.assertEqual(0, len(list(checks.check_python3_no_itervalues(
"obj.values()"))))

View File

@ -658,7 +658,7 @@ class TestHelpers(test_utils.BaseTestCase):
'location': "file:///tmp/glance-tests/2", 'location': "file:///tmp/glance-tests/2",
'properties': {'distro': 'Ubuntu 10.04 LTS'}} 'properties': {'distro': 'Ubuntu 10.04 LTS'}}
headers = utils.image_meta_to_http_headers(fixture) headers = utils.image_meta_to_http_headers(fixture)
for k, v in six.iteritems(headers): for k, v in headers.items():
self.assertIsInstance(v, six.text_type) self.assertIsInstance(v, six.text_type)
def test_data_passed_properly_through_headers(self): def test_data_passed_properly_through_headers(self):
@ -679,7 +679,7 @@ class TestHelpers(test_utils.BaseTestCase):
response = FakeResponse() response = FakeResponse()
response.headers = headers response.headers = headers
result = utils.get_image_meta_from_headers(response) result = utils.get_image_meta_from_headers(response)
for k, v in six.iteritems(fixture): for k, v in fixture.items():
if v is not None: if v is not None:
self.assertEqual(v, result[k]) self.assertEqual(v, result[k])
else: else:

View File

@ -142,9 +142,6 @@ extension =
G327 = checks:check_no_contextlib_nested G327 = checks:check_no_contextlib_nested
G328 = checks:dict_constructor_with_list_copy G328 = checks:dict_constructor_with_list_copy
G329 = checks:check_python3_xrange G329 = checks:check_python3_xrange
G330 = checks:check_python3_no_iteritems
G331 = checks:check_python3_no_iterkeys
G332 = checks:check_python3_no_itervalues
paths = ./glance/hacking paths = ./glance/hacking
[testenv:docs] [testenv:docs]