From 0edbd7a5484c870fc3e7c7fc1b22494ba4f5cef2 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Tue, 20 Dec 2022 11:36:36 +0800 Subject: [PATCH] [CodeStyle][py2] cleanup some useless comments related to py2 (#49135) --- .pre-commit-config.yaml | 2 +- .../paddle/distributed/fleet/utils/http_server.py | 2 -- python/paddle/fluid/dataloader/dataloader_iter.py | 1 - python/paddle/fluid/dataloader/worker.py | 1 - python/paddle/fluid/dygraph/checkpoint.py | 1 - python/paddle/fluid/framework.py | 15 ++++++--------- .../fluid/incubate/fleet/utils/http_server.py | 1 - python/paddle/fluid/multiprocess_utils.py | 1 - python/paddle/fluid/reader.py | 1 - tools/sampcd_processor.py | 2 +- tools/test_print_signatures.py | 6 ++---- 11 files changed, 10 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e916caff91..bd09715e0a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ exclude: | paddle/fluid/framework/fleet/heter_ps/cudf/.+| paddle/fluid/distributed/ps/thirdparty/round_robin.h| python/paddle/utils/gast/.+| - .+_py2\.py| + .+_pb2\.py| python/paddle/fluid/tests/unittests/npu/.+| python/paddle/fluid/tests/unittests/mlu/.+ )$ diff --git a/python/paddle/distributed/fleet/utils/http_server.py b/python/paddle/distributed/fleet/utils/http_server.py index 4caab0efaa..c284e9779d 100644 --- a/python/paddle/distributed/fleet/utils/http_server.py +++ b/python/paddle/distributed/fleet/utils/http_server.py @@ -16,8 +16,6 @@ import http.server as SimpleHTTPServer import logging import threading - -# NOTE: HTTPServer has a different name in python2 and python3 from http.server import HTTPServer __all__ = [] diff --git a/python/paddle/fluid/dataloader/dataloader_iter.py b/python/paddle/fluid/dataloader/dataloader_iter.py index e47d75326b..620bd51378 100644 --- a/python/paddle/fluid/dataloader/dataloader_iter.py +++ b/python/paddle/fluid/dataloader/dataloader_iter.py @@ -28,7 +28,6 @@ from paddle.fluid.framework import ( set_flags, ) -# NOTE: queue has a different name in python2 and python3 import queue import paddle diff --git a/python/paddle/fluid/dataloader/worker.py b/python/paddle/fluid/dataloader/worker.py index 64ec697cf5..e63a5d5f93 100644 --- a/python/paddle/fluid/dataloader/worker.py +++ b/python/paddle/fluid/dataloader/worker.py @@ -28,7 +28,6 @@ from ..multiprocess_utils import ( from ..framework import _non_static_mode, _in_eager_without_dygraph_check from .flat import _flatten_batch -# NOTE: queue has a different name in python2 and python3 import queue __all__ = ['get_worker_info'] diff --git a/python/paddle/fluid/dygraph/checkpoint.py b/python/paddle/fluid/dygraph/checkpoint.py index 8103f1f82b..2078f0fcf0 100644 --- a/python/paddle/fluid/dygraph/checkpoint.py +++ b/python/paddle/fluid/dygraph/checkpoint.py @@ -248,7 +248,6 @@ def load_dygraph(model_path, **configs): ) # 2. load layer parameters & buffers - # NOTE: using fluid.dygraph.guard() here will cause import error in py2 with guard(): persistable_var_dict = _construct_params_and_buffers( model_prefix, diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 4f56306e5e..383cf6eb61 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -1290,7 +1290,7 @@ def _varbase_creator( shape=None, dtype=None, persistable=None, - **kwargs + **kwargs, ): if dtype is not None: if not isinstance(dtype, core.VarDesc.VarType): @@ -1412,7 +1412,7 @@ class Variable(metaclass=VariableMetaClass): is_data=False, need_check_feed=False, belong_to_optimizer=False, - **kwargs + **kwargs, ): self.block = block if name is None: @@ -2953,11 +2953,8 @@ class Operator: in_arg_names.append(arg.name) else: raise TypeError( - "The type of '%s' in operator %s should be " - "one of [basestring(), str, Varibale] in python2, " - "or one of [str, bytes, Variable] in python3." - "but received : %s" - % (in_proto.name, type, arg) + f"The type of '%{in_proto.name}' in operator {type} should be " + f"one of [str, bytes, Variable]. but received : {arg}" ) self.desc.set_input(in_proto.name, in_arg_names) else: @@ -6887,7 +6884,7 @@ class Parameter(Variable, metaclass=ParameterMetaClass): shape, dtype, type=core.VarDesc.VarType.LOD_TENSOR, - **kwargs + **kwargs, ): if shape is None: raise ValueError("The shape of Parameter should not be None") @@ -6908,7 +6905,7 @@ class Parameter(Variable, metaclass=ParameterMetaClass): shape=shape, dtype=dtype, type=type, - **kwargs + **kwargs, ) self.trainable = kwargs.get('trainable', True) diff --git a/python/paddle/fluid/incubate/fleet/utils/http_server.py b/python/paddle/fluid/incubate/fleet/utils/http_server.py index 79b436ff40..4da8afcaae 100644 --- a/python/paddle/fluid/incubate/fleet/utils/http_server.py +++ b/python/paddle/fluid/incubate/fleet/utils/http_server.py @@ -15,7 +15,6 @@ import logging -# NOTE: HTTPServer has a different name in python2 and python3 from http.server import HTTPServer import http.server as SimpleHTTPServer import time diff --git a/python/paddle/fluid/multiprocess_utils.py b/python/paddle/fluid/multiprocess_utils.py index deca95457e..bc7d58d128 100644 --- a/python/paddle/fluid/multiprocess_utils.py +++ b/python/paddle/fluid/multiprocess_utils.py @@ -18,7 +18,6 @@ import atexit from . import core -# NOTE: queue has a different name in python2 and python3 import queue # multi-process worker check indices queue interval, avoid diff --git a/python/paddle/fluid/reader.py b/python/paddle/fluid/reader.py index 104ac8d864..90e5f71b4f 100644 --- a/python/paddle/fluid/reader.py +++ b/python/paddle/fluid/reader.py @@ -64,7 +64,6 @@ import os import multiprocessing import signal -# NOTE: queue has a different name in python2 and python3 import queue # NOTE: [ avoid hanging & failed quickly ] These value is used in getting data from another process diff --git a/tools/sampcd_processor.py b/tools/sampcd_processor.py index 742cb3f7c7..fb09e4e258 100644 --- a/tools/sampcd_processor.py +++ b/tools/sampcd_processor.py @@ -16,7 +16,7 @@ please make sure to run in the tools path usage: python sample_test.py {cpu or gpu} {cpu or gpu}: running in cpu version or gpu version -for example, you can run cpu version python2 testing like this: +for example, you can run cpu version testing like this: python sampcd_processor.py cpu diff --git a/tools/test_print_signatures.py b/tools/test_print_signatures.py index 0c3e17c7fa..92ca9deedd 100644 --- a/tools/test_print_signatures.py +++ b/tools/test_print_signatures.py @@ -67,9 +67,7 @@ class Test_is_primitive(unittest.TestCase): self.assertTrue(is_primitive(2)) self.assertTrue(is_primitive(2.1)) self.assertTrue(is_primitive("2.1.1")) - self.assertFalse( - is_primitive("hello paddle".encode('UTF-8')) - ) # True for python2 + self.assertFalse(is_primitive("hello paddle".encode('UTF-8'))) self.assertFalse(is_primitive(1j)) self.assertTrue(is_primitive(True)) @@ -80,7 +78,7 @@ class Test_is_primitive(unittest.TestCase): self.assertTrue(is_primitive([1, 2])) self.assertTrue(is_primitive((1.1, 2.2))) self.assertTrue(is_primitive(set([1, 2.3]))) - self.assertFalse(is_primitive(range(3))) # True for python2 + self.assertFalse(is_primitive(range(3))) self.assertFalse(is_primitive({})) self.assertFalse(is_primitive([1, 1j])) -- GitLab