diff --git a/python/paddle/distribution/multinomial.py b/python/paddle/distribution/multinomial.py index 0408aa9a6065aba16f5b5e8dc67bcfc47dd9e8a8..5630fd146918903126bdf9bd88b9b9d91ed7e10d 100644 --- a/python/paddle/distribution/multinomial.py +++ b/python/paddle/distribution/multinomial.py @@ -15,10 +15,7 @@ import paddle from paddle.distribution import categorical, distribution -try: - from collections.abc import Iterable -except: - from collections import Iterable +from collections.abc import Iterable class Multinomial(distribution.Distribution): diff --git a/python/paddle/distribution/normal.py b/python/paddle/distribution/normal.py index 061d68ab5afa0607b41d455ed0f70bf16a4a9ac6..0dd7db2df9e4d1adb2a953b0c85d5f07d6f29851 100644 --- a/python/paddle/distribution/normal.py +++ b/python/paddle/distribution/normal.py @@ -26,10 +26,7 @@ from paddle.fluid.layers import ( tensor, ) -try: - from collections.abc import Iterable -except: - from collections import Iterable +from collections.abc import Iterable class Normal(distribution.Distribution): diff --git a/python/paddle/fluid/backward.py b/python/paddle/fluid/backward.py index 279ac480453dd7b2ced706e5936fb438198d5f66..8f8b4bfa7311538f6209bece93d143dfb50b12d6 100755 --- a/python/paddle/fluid/backward.py +++ b/python/paddle/fluid/backward.py @@ -26,10 +26,7 @@ import paddle.fluid from .data_feeder import check_type import warnings -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence __all__ = [ 'append_backward', diff --git a/python/paddle/fluid/dataloader/collate.py b/python/paddle/fluid/dataloader/collate.py index 661a0de13cd517dfb4aead02d196efd6818b7c37..dd70a3421409db170e77aac72891aaccd03365ed 100644 --- a/python/paddle/fluid/dataloader/collate.py +++ b/python/paddle/fluid/dataloader/collate.py @@ -18,10 +18,7 @@ import numpy as np from ..framework import _non_static_mode from .. import core, layers -try: - from collections.abc import Sequence, Mapping -except: - from collections import Sequence, Mapping +from collections.abc import Sequence, Mapping def default_collate_fn(batch): diff --git a/python/paddle/fluid/dataloader/flat.py b/python/paddle/fluid/dataloader/flat.py index 6f3c6edf0b0ccde5c7a790abe1f8bbed90357b02..1e1ed1eebd8064b7195d40210e06c78642d922cc 100644 --- a/python/paddle/fluid/dataloader/flat.py +++ b/python/paddle/fluid/dataloader/flat.py @@ -16,10 +16,8 @@ import paddle import numbers import numpy as np -try: - from collections.abc import Sequence, Mapping -except: - from collections import Sequence, Mapping +from collections.abc import Sequence, Mapping + FIELD_PREFIX = "_paddle_field_" diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py b/python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py index d6ff463a70d7cd546d16c3defcfa1be82f2ce18f..7eb9da1206439d7d86c6b0f62942ff81e38d6d06 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py @@ -21,10 +21,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import unwrap from paddle.fluid.dygraph.dygraph_to_static.utils import ORIGI_INFO from paddle.fluid.framework import Program -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence class Location: diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index b32124e6bc471a58686dc1f9f1652da91f22b3df..076fdf8fdb105a4f3c230896c73dfe34b1d23d68 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -59,6 +59,8 @@ from ..data_feeder import ( ) from paddle.utils import deprecated from paddle import _C_ops, _legacy_C_ops +from collections.abc import Iterable + __all__ = [ 'fc', @@ -6798,10 +6800,6 @@ def lod_append(x, level): x = fluid.layers.data(name='x', shape=[6, 10], lod_level=1) out = fluid.layers.lod_append(x, [1,1,1,1,1,1]) """ - try: - from collections.abc import Iterable - except: - from collections import Iterable if x is None: raise ValueError("Input(x) can't be None.") if (not isinstance(level, Iterable)) and (not isinstance(level, Variable)): diff --git a/python/paddle/fluid/layers/rnn.py b/python/paddle/fluid/layers/rnn.py index 60b0eb5da67d057acb0ac9e99cc701d450465593..82da847bbc7b697571b112c51852444d275ce313 100644 --- a/python/paddle/fluid/layers/rnn.py +++ b/python/paddle/fluid/layers/rnn.py @@ -32,10 +32,7 @@ from ..framework import _non_static_mode from ..param_attr import ParamAttr from ..data_feeder import check_variable_and_dtype, check_type, check_dtype -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence __all__ = [ 'RNNCell', diff --git a/python/paddle/fluid/layers/utils.py b/python/paddle/fluid/layers/utils.py index 66fc253bb097b95ab10a95c9d70eaa50d8ae0e65..7e3e69fda7c07272ab07f336da641af99412b9e9 100644 --- a/python/paddle/fluid/layers/utils.py +++ b/python/paddle/fluid/layers/utils.py @@ -25,10 +25,7 @@ from ..data_feeder import ( from ..layer_helper import LayerHelper from sys import version_info -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence def convert_to_list(value, n, name, dtype=int): diff --git a/python/paddle/fluid/tests/unittests/gradient_checker.py b/python/paddle/fluid/tests/unittests/gradient_checker.py index 9b08f17dadd7bb00c638aebd2c64453a9ebc44d3..c51b02bd43b5544e87d1a7ae9721d35be6b55706 100644 --- a/python/paddle/fluid/tests/unittests/gradient_checker.py +++ b/python/paddle/fluid/tests/unittests/gradient_checker.py @@ -22,10 +22,7 @@ import paddle.fluid.core as core from paddle.fluid.backward import _append_grad_suffix_, _as_list from paddle.fluid.framework import _test_eager_guard -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence def _product(t): diff --git a/python/paddle/framework/io.py b/python/paddle/framework/io.py index 758f734dd9ac73c77b5777922c7fa0ebbeaa507d..57e1edfc478c00a60678a041402bb52999a0b168 100644 --- a/python/paddle/framework/io.py +++ b/python/paddle/framework/io.py @@ -49,10 +49,7 @@ from paddle.fluid.dygraph.io import ( ) from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX -try: - from collections.abc import Iterable -except: - from collections import Iterable +from collections.abc import Iterable __all__ = [] diff --git a/python/paddle/nn/layer/rnn.py b/python/paddle/nn/layer/rnn.py index dba69b9848a289c54df74cc6b563f9df18afbb5f..aeac50d0680e1a8d6e79c2fff810299ec996591c 100644 --- a/python/paddle/nn/layer/rnn.py +++ b/python/paddle/nn/layer/rnn.py @@ -30,10 +30,7 @@ from paddle.framework import core from paddle.static import default_startup_program from paddle.static import program_guard -try: - from collections.abc import Sequence -except: - from collections import Sequence +from collections.abc import Sequence __all__ = [] diff --git a/python/paddle/vision/transforms/functional_cv2.py b/python/paddle/vision/transforms/functional_cv2.py index 52609b786fe1f5376e0f2d2117d2451996aa104a..f22b63d83f87117cb3231eba3be0126cccc408f9 100644 --- a/python/paddle/vision/transforms/functional_cv2.py +++ b/python/paddle/vision/transforms/functional_cv2.py @@ -12,22 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import math import numbers -import collections import numpy as np import paddle from paddle.utils import try_import -if sys.version_info < (3, 3): - Sequence = collections.Sequence - Iterable = collections.Iterable -else: - Sequence = collections.abc.Sequence - Iterable = collections.abc.Iterable +from collections.abc import Sequence, Iterable __all__ = [] diff --git a/python/paddle/vision/transforms/functional_pil.py b/python/paddle/vision/transforms/functional_pil.py index 595d92a84b11b0c388cbd5ccc748f63a906f2e01..432cd7da2bd8abce8820d2c687a6401af90ad140 100644 --- a/python/paddle/vision/transforms/functional_pil.py +++ b/python/paddle/vision/transforms/functional_pil.py @@ -12,20 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import numbers -import collections from PIL import Image, ImageOps, ImageEnhance import numpy as np import paddle -if sys.version_info < (3, 3): - Sequence = collections.Sequence - Iterable = collections.Iterable -else: - Sequence = collections.abc.Sequence - Iterable = collections.abc.Iterable +from collections.abc import Sequence, Iterable try: # PIL version >= "9.1.0" diff --git a/python/paddle/vision/transforms/transforms.py b/python/paddle/vision/transforms/transforms.py index f5cbd90ffc7b0d8a5023f42122f4bd463f552c7e..13be056df2daf62f1105a91384d379a53f5071cc 100644 --- a/python/paddle/vision/transforms/transforms.py +++ b/python/paddle/vision/transforms/transforms.py @@ -13,23 +13,16 @@ # limitations under the License. import math -import sys import random import numpy as np import numbers -import collections import traceback import paddle from . import functional as F -if sys.version_info < (3, 3): - Sequence = collections.Sequence - Iterable = collections.Iterable -else: - Sequence = collections.abc.Sequence - Iterable = collections.abc.Iterable +from collections.abc import Sequence, Iterable __all__ = []