From 85c5c6182e9a55154f350a5dc1bb8d9975e338ef Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Mon, 4 Nov 2019 12:51:56 +0000 Subject: [PATCH] remove python 2 specific code --- lib/iris/_constraints.py | 5 +---- lib/iris/analysis/__init__.py | 5 +---- lib/iris/coords.py | 5 +---- lib/iris/cube.py | 9 +-------- lib/iris/fileformats/cf.py | 5 +---- lib/iris/io/format_picker.py | 5 +---- lib/iris/iterate.py | 5 +---- lib/iris/tests/test_merge.py | 5 +---- .../tests/unit/analysis/maths/test__output_dtype.py | 5 ----- lib/iris/tests/unit/analysis/maths/test_divide.py | 10 ++-------- lib/iris/util.py | 5 +---- 11 files changed, 11 insertions(+), 53 deletions(-) diff --git a/lib/iris/_constraints.py b/lib/iris/_constraints.py index d08e952968..012fbfe4ba 100644 --- a/lib/iris/_constraints.py +++ b/lib/iris/_constraints.py @@ -12,10 +12,7 @@ from six.moves import (filter, input, map, range, zip) # noqa import six -try: # Python 3 - from collections.abc import Iterable, Mapping -except ImportError: # Python 2.7 - from collections import Iterable, Mapping +from collections.abc import Iterable, Mapping import operator import numpy as np diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 2244db8231..1f1385d653 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -40,10 +40,7 @@ import six from collections import OrderedDict -try: # Python 3 - from collections.abc import Iterable -except ImportError: # Python 2.7 - from collections import Iterable +from collections.abc import Iterable from functools import wraps import dask.array as da diff --git a/lib/iris/coords.py b/lib/iris/coords.py index 2aa7f542f9..74d2a3707f 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -14,10 +14,7 @@ from abc import ABCMeta from collections import namedtuple -try: # Python 3 - from collections.abc import Iterator -except ImportError: # Python 2.7 - from collections import Iterator +from collections.abc import Iterator import copy from itertools import chain from six.moves import zip_longest diff --git a/lib/iris/cube.py b/lib/iris/cube.py index e5257b7060..b3d63a343e 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -14,14 +14,7 @@ import six from collections import namedtuple, OrderedDict -try: # Python 3 - from collections.abc import (Iterable, - Container, - Mapping, - MutableMapping, - Iterator) -except ImportError: # Python 2.7 - from collections import (Iterable, +from collections.abc import (Iterable, Container, Mapping, MutableMapping, diff --git a/lib/iris/fileformats/cf.py b/lib/iris/fileformats/cf.py index 1917f8a3e1..ca79cc84e3 100644 --- a/lib/iris/fileformats/cf.py +++ b/lib/iris/fileformats/cf.py @@ -20,10 +20,7 @@ from abc import ABCMeta, abstractmethod -try: # Python 3 - from collections.abc import Iterable, MutableMapping -except ImportError: # Python 2.7 - from collections import Iterable, MutableMapping +from collections.abc import Iterable, MutableMapping import os import re import warnings diff --git a/lib/iris/io/format_picker.py b/lib/iris/io/format_picker.py index e2ab57e930..a014b22786 100644 --- a/lib/iris/io/format_picker.py +++ b/lib/iris/io/format_picker.py @@ -44,10 +44,7 @@ from six.moves import (filter, input, map, range, zip) # noqa import six -try: # Python 3 - from collections.abc import Callable -except ImportError: # Python 2.7 - from collections import Callable +from collections.abc import Callable import functools import os import struct diff --git a/lib/iris/iterate.py b/lib/iris/iterate.py index 9dcd086614..fd680c2380 100644 --- a/lib/iris/iterate.py +++ b/lib/iris/iterate.py @@ -11,10 +11,7 @@ from __future__ import (absolute_import, division, print_function) from six.moves import (filter, input, map, range, zip) # noqa -try: # Python 3 - from collections.abc import Iterator -except ImportError: # Python 2.7 - from collections import Iterator +from collections.abc import Iterator import itertools import warnings diff --git a/lib/iris/tests/test_merge.py b/lib/iris/tests/test_merge.py index 9735aaa646..60dd1b3e15 100644 --- a/lib/iris/tests/test_merge.py +++ b/lib/iris/tests/test_merge.py @@ -15,10 +15,7 @@ # import iris tests first so that some things can be initialised before importing anything else import iris.tests as tests -try: # Python 3 - from collections.abc import Iterable -except ImportError: # Python 2.7 - from collections import Iterable +from collections.abc import Iterable import datetime import itertools import numpy as np diff --git a/lib/iris/tests/unit/analysis/maths/test__output_dtype.py b/lib/iris/tests/unit/analysis/maths/test__output_dtype.py index 39c74a234a..257047bd45 100644 --- a/lib/iris/tests/unit/analysis/maths/test__output_dtype.py +++ b/lib/iris/tests/unit/analysis/maths/test__output_dtype.py @@ -37,11 +37,6 @@ def setUp(self): np.multiply, np.power, np.floor_divide] - try: - self.same_result_ops.append(operator.div) - except AttributeError: - # operator.div doesn't exist in Python 3 - pass self.unary_same_result_ops = [np.abs] diff --git a/lib/iris/tests/unit/analysis/maths/test_divide.py b/lib/iris/tests/unit/analysis/maths/test_divide.py index 1180be8845..a0bea86271 100644 --- a/lib/iris/tests/unit/analysis/maths/test_divide.py +++ b/lib/iris/tests/unit/analysis/maths/test_divide.py @@ -28,10 +28,7 @@ class TestBroadcasting(tests.IrisTest_nometa, CubeArithmeticBroadcastingTestMixin): @property def data_op(self): - try: - return operator.div - except AttributeError: - return operator.truediv + return operator.truediv @property def cube_func(self): @@ -42,10 +39,7 @@ def cube_func(self): class TestMasking(tests.IrisTest_nometa, CubeArithmeticMaskingTestMixin): @property def data_op(self): - try: - return operator.div - except AttributeError: - return operator.truediv + return operator.truediv @property def cube_func(self): diff --git a/lib/iris/util.py b/lib/iris/util.py index f8cc859cd2..20f7786f24 100644 --- a/lib/iris/util.py +++ b/lib/iris/util.py @@ -12,10 +12,7 @@ from six.moves import (filter, input, map, range, zip) # noqa import six -try: # Python 3 - from collections.abc import Hashable -except ImportError: # Python 2.7 - from collections import Hashable +from collections.abc import Hashable import abc from contextlib import contextmanager import copy