diff --git a/HACKING.rst b/HACKING.rst index 86be947087..b0aa39efe5 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -20,6 +20,3 @@ glance Specific Commandments - [G328] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs - [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. diff --git a/glance/common/client.py b/glance/common/client.py index 01ea13e776..30730617cd 100644 --- a/glance/common/client.py +++ b/glance/common/client.py @@ -417,7 +417,7 @@ class BaseClient(object): to_str = str else: 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 def _do_request(self, method, url, body, headers): diff --git a/glance/common/location_strategy/store_type.py b/glance/common/location_strategy/store_type.py index 2401a2155b..2b649c4912 100644 --- a/glance/common/location_strategy/store_type.py +++ b/glance/common/location_strategy/store_type.py @@ -16,7 +16,6 @@ """Storage preference based location strategy module""" from oslo_config import cfg -import six import six.moves.urllib.parse as urlparse from glance.i18n import _ @@ -116,7 +115,7 @@ def get_ordered_locations(locations, uri_key='url', **kwargs): pieces = urlparse.urlparse(uri.strip()) 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: store_name = store break diff --git a/glance/common/utils.py b/glance/common/utils.py index f834da1a72..59a1e5a020 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -384,10 +384,9 @@ def create_mashup_dict(image_meta): """ d = {} - for key, value in six.iteritems(image_meta): + for key, value in image_meta.items(): if isinstance(value, dict): - for subkey, subvalue in six.iteritems( - create_mashup_dict(value)): + for subkey, subvalue in create_mashup_dict(value).items(): if subkey not in image_meta: d[subkey] = subvalue else: @@ -522,7 +521,7 @@ def no_4byte_params(f): def _check_dict(data_dict): # 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): _check_dict(value) else: diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 9379369240..820e18b598 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -947,7 +947,7 @@ class Debug(Middleware): resp = req.get_response(self.application) print(("*" * 40) + " RESPONSE HEADERS") - for (key, value) in six.iteritems(resp.headers): + for key, value in resp.headers.items(): print(key, "=", value) print('') diff --git a/glance/db/simple/api.py b/glance/db/simple/api.py index 1a0096ba22..10f77c48dc 100644 --- a/glance/db/simple/api.py +++ b/glance/db/simple/api.py @@ -20,7 +20,6 @@ import uuid from oslo_config import cfg from oslo_log import log as logging -import six from glance.common import exception from glance.common import timeutils @@ -312,7 +311,7 @@ def _filter_images(images, filters, context, continue to_add = True - for k, value in six.iteritems(filters): + for k, value in filters.items(): key = k if k.endswith('_min') or k.endswith('_max'): key = key[0:-4] @@ -1092,7 +1091,7 @@ def _filter_tasks(tasks, filters, context, admin_as_user=False): continue add = True - for k, value in six.iteritems(filters): + for k, value in filters.items(): add = task[k] == value and task['deleted'] is False if not add: break diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index 48dfd0e45f..7df5f19697 100644 --- a/glance/db/sqlalchemy/api.py +++ b/glance/db/sqlalchemy/api.py @@ -1175,7 +1175,7 @@ def _set_properties_for_image(context, image_ref, properties, for prop_ref in image_ref.properties: 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, 'name': name, 'value': value} diff --git a/glance/db/sqlalchemy/metadata.py b/glance/db/sqlalchemy/metadata.py index 3f11b8e9a0..f0685eae78 100644 --- a/glance/db/sqlalchemy/metadata.py +++ b/glance/db/sqlalchemy/metadata.py @@ -26,7 +26,6 @@ import re from oslo_config import cfg from oslo_log import log as logging from oslo_utils import encodeutils -import six import sqlalchemy from sqlalchemy import and_ 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, rt_id, namespace_id) - for property, schema in six.iteritems(metadata.get('properties', - {})): + for name, schema in metadata.get('properties', {}).items(): values = { - 'name': property, + 'name': name, 'namespace_id': namespace_id, 'json_schema': json.dumps(schema) } - property_id = _get_resource_id(properties_table, - namespace_id, property) + property_id = _get_resource_id( + properties_table, namespace_id, name, + ) if not property_id: values.update({'created_at': timeutils.utcnow()}) _insert_data_to_db(properties_table, values) diff --git a/glance/hacking/checks.py b/glance/hacking/checks.py index a902b06b32..a5cc6222f1 100644 --- a/glance/hacking/checks.py +++ b/glance/hacking/checks.py @@ -131,27 +131,3 @@ def check_python3_xrange(logical_line): if re.search(r"\bxrange\s*\(", logical_line): yield(0, "G329: Do not use xrange. Use range, or six.moves.range for " "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) diff --git a/glance/notifier.py b/glance/notifier.py index b55d59980a..ea25be1914 100644 --- a/glance/notifier.py +++ b/glance/notifier.py @@ -22,7 +22,6 @@ from oslo_log import log as logging import oslo_messaging from oslo_utils import encodeutils from oslo_utils import excutils -import six import webob from glance.common import exception @@ -219,7 +218,7 @@ def format_metadef_namespace_notification(metadef_namespace): def format_metadef_object_notification(metadef_object): object_properties = metadef_object.properties or {} properties = [] - for name, prop in six.iteritems(object_properties): + for name, prop in object_properties.items(): object_property = _format_metadef_object_property(name, prop) properties.append(object_property) diff --git a/glance/schema.py b/glance/schema.py index f1bf431061..a20725bde3 100644 --- a/glance/schema.py +++ b/glance/schema.py @@ -15,7 +15,6 @@ import jsonschema from oslo_utils import encodeutils -import six from glance.common import exception from glance.i18n import _ @@ -42,7 +41,7 @@ class Schema(object): def filter(self, obj): filtered = {} - for key, value in six.iteritems(obj): + for key, value in obj.items(): if self._filter_func(self.properties, key): filtered[key] = value diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index 3f98527918..124a0e92c3 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -1516,7 +1516,7 @@ class TestImages(functional.FunctionalTest): 'min_ram': 0, '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) # Upload data to image @@ -1586,7 +1586,7 @@ class TestImages(functional.FunctionalTest): '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) # Upload data to image @@ -1658,7 +1658,7 @@ class TestImages(functional.FunctionalTest): '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) # Upload data to image diff --git a/glance/tests/test_hacking.py b/glance/tests/test_hacking.py index 53b3926bb7..3bd0c00597 100644 --- a/glance/tests/test_hacking.py +++ b/glance/tests/test_hacking.py @@ -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 six.moves.range(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()")))) diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index 98726e729d..09700872e8 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -658,7 +658,7 @@ class TestHelpers(test_utils.BaseTestCase): 'location': "file:///tmp/glance-tests/2", 'properties': {'distro': 'Ubuntu 10.04 LTS'}} 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) def test_data_passed_properly_through_headers(self): @@ -679,7 +679,7 @@ class TestHelpers(test_utils.BaseTestCase): response = FakeResponse() response.headers = headers 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: self.assertEqual(v, result[k]) else: diff --git a/tox.ini b/tox.ini index acd3473d06..59e32b56ac 100644 --- a/tox.ini +++ b/tox.ini @@ -142,9 +142,6 @@ extension = G327 = checks:check_no_contextlib_nested G328 = checks:dict_constructor_with_list_copy 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 [testenv:docs]