From: James Page Date: Thu, 29 Nov 2018 09:47:07 +0000 (+0000) Subject: Correct usage of collections.abc X-Git-Tag: v14.1.0~766^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=20aa3ad17b467f823b2b9512af050c688558ef1f;p=ceph.git Correct usage of collections.abc Some classes should still be imported directly from collections; only OrderedDict, Iterable and Callable (in the context of the ceph codebase) are found in collections.abc. The current code works due to the fallback support for Python 2. Signed-off-by: James Page --- diff --git a/qa/tasks/cephfs/test_data_scan.py b/qa/tasks/cephfs/test_data_scan.py index 478d2a12a652..0faeb43fc03f 100644 --- a/qa/tasks/cephfs/test_data_scan.py +++ b/qa/tasks/cephfs/test_data_scan.py @@ -8,10 +8,7 @@ import logging import os from textwrap import dedent import traceback -try: - from collections.abc import namedtuple, defaultdict -except ImportError: - from collections import namedtuple, defaultdict +from collections import namedtuple, defaultdict from teuthology.orchestra.run import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology diff --git a/qa/tasks/cephfs/test_forward_scrub.py b/qa/tasks/cephfs/test_forward_scrub.py index 6150dbaea4a1..e165780f31f1 100644 --- a/qa/tasks/cephfs/test_forward_scrub.py +++ b/qa/tasks/cephfs/test_forward_scrub.py @@ -10,10 +10,7 @@ how the functionality responds to damaged metadata. import json import logging -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple from textwrap import dedent from teuthology.orchestra.run import CommandFailedError diff --git a/qa/tasks/cephfs/test_recovery_pool.py b/qa/tasks/cephfs/test_recovery_pool.py index 41fd512f1188..97049b9c0a33 100644 --- a/qa/tasks/cephfs/test_recovery_pool.py +++ b/qa/tasks/cephfs/test_recovery_pool.py @@ -8,10 +8,7 @@ import logging import os from textwrap import dedent import traceback -try: - from collections.abc import namedtuple, defaultdict -except ImportError: - from collections import namedtuple, defaultdict +from collections import namedtuple, defaultdict from teuthology.orchestra.run import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology diff --git a/qa/tasks/cephfs/test_scrub.py b/qa/tasks/cephfs/test_scrub.py index 4cc4f7f0c94b..9469dfce6e49 100644 --- a/qa/tasks/cephfs/test_scrub.py +++ b/qa/tasks/cephfs/test_scrub.py @@ -4,10 +4,7 @@ Test CephFS scrub (distinct from OSD scrub) functionality import logging import os import traceback -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple from teuthology.orchestra.run import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index 9b8444e62ccc..13fc8480b7a3 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -4,10 +4,7 @@ from __future__ import absolute_import import json import logging -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple import time import requests diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index 8afafb59eebf..bf54af492193 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -26,10 +26,7 @@ Alternative usage: """ from StringIO import StringIO -try: - from collections.abc import defaultdict -except ImportError: - from collections import defaultdict +from collections import defaultdict import getpass import signal import tempfile diff --git a/src/ceph-volume/ceph_volume/__init__.py b/src/ceph-volume/ceph_volume/__init__.py index fd997eea7089..640fb1e6fb15 100644 --- a/src/ceph-volume/ceph_volume/__init__.py +++ b/src/ceph-volume/ceph_volume/__init__.py @@ -1,7 +1,4 @@ -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple sys_info = namedtuple('sys_info', ['devices']) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 2fb748090cba..5f6ee6562b1f 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -9,10 +9,7 @@ from libc.stdlib cimport malloc, realloc, free cimport rados -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple from datetime import datetime import errno import os diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index d481e493e7ec..df31d4a4f36e 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -try: - from collections.abc import defaultdict -except ImportError: - from collections import defaultdict +from collections import defaultdict import cherrypy diff --git a/src/pybind/mgr/dashboard/services/ceph_service.py b/src/pybind/mgr/dashboard/services/ceph_service.py index b0bec642a1a2..91b4f351ef6e 100644 --- a/src/pybind/mgr/dashboard/services/ceph_service.py +++ b/src/pybind/mgr/dashboard/services/ceph_service.py @@ -2,12 +2,8 @@ from __future__ import absolute_import import time -try: - import collections.abc - from collections.abc import defaultdict -except ImportError: - import collections - from collections import defaultdict +import collections +from collections import defaultdict import json import rados diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 5d582039aeda..fbdd3f1f4207 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -5,10 +5,7 @@ import logging import json import six import threading -try: - from collections.abc import defaultdict, namedtuple -except ImportError: - from collections import defaultdict, namedtuple +from collections import defaultdict, namedtuple import rados import time diff --git a/src/pybind/mgr/restful/api/crush.py b/src/pybind/mgr/restful/api/crush.py index 6b2b3646cf96..ee8589df0a41 100644 --- a/src/pybind/mgr/restful/api/crush.py +++ b/src/pybind/mgr/restful/api/crush.py @@ -2,10 +2,7 @@ from pecan import expose from pecan.rest import RestController from restful import common, context -try: - from collections.abc import defaultdict -except ImportError: - from collections import defaultdict +from collections import defaultdict from restful.decorators import auth diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index 7a4f72cb3cdb..99d3c7103d5b 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -3,10 +3,7 @@ High level status display commands """ -try: - from collections.abc import defaultdict -except ImportError: - from collections import defaultdict +from collections import defaultdict from prettytable import PrettyTable import errno import fnmatch diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index d20b24979b55..f331e1825326 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -12,10 +12,7 @@ import uuid import time from datetime import datetime from threading import Event -try: - from collections.abc import defaultdict -except ImportError: - from collections import defaultdict +from collections import defaultdict from mgr_module import MgrModule diff --git a/src/pybind/rgw/rgw.pyx b/src/pybind/rgw/rgw.pyx index 39476aac86f8..f512d33f84ab 100644 --- a/src/pybind/rgw/rgw.pyx +++ b/src/pybind/rgw/rgw.pyx @@ -10,10 +10,7 @@ from libc.stdlib cimport malloc, realloc, free cimport rados -try: - from collections.abc import namedtuple -except ImportError: - from collections import namedtuple +from collections import namedtuple from datetime import datetime import errno diff --git a/src/tools/rgw/parse-cr-dump.py b/src/tools/rgw/parse-cr-dump.py index e979cf33ec8f..539929b113d8 100755 --- a/src/tools/rgw/parse-cr-dump.py +++ b/src/tools/rgw/parse-cr-dump.py @@ -1,9 +1,6 @@ #!/usr/bin/python from __future__ import print_function -try: - from collections.abc import Counter -except ImportError: - from collections import Counter +from collections import Counter import argparse import json import re