From 8c888eea99307f576f5f26d05f12c4c83a6b4184 Mon Sep 17 00:00:00 2001 From: Infinity_lee Date: Tue, 28 Mar 2023 09:28:46 +0800 Subject: [PATCH] [CodeStyle][UP024] Replace aliased errors with OSError (#52024) --- .../fleet/meta_parallel/sharding/group_sharded_utils.py | 2 +- python/paddle/jit/dy2static/convert_call_func.py | 8 ++++---- tools/CrossStackProfiler/CspFileReader.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_utils.py b/python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_utils.py index 27c508b279f..1a09bb3fa92 100644 --- a/python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_utils.py +++ b/python/paddle/distributed/fleet/meta_parallel/sharding/group_sharded_utils.py @@ -318,7 +318,7 @@ def cvt_to_device(x, dev_id, blocking=True): elif paddle.is_compiled_with_xpu(): place = paddle.XPUPlace(dev_id) else: - raise EnvironmentError( + raise OSError( "Only supported compiled paddle with gpu/rocm, npu and xpu , but current verison is compiled with cpu." ) return x._copy_to(place, blocking) diff --git a/python/paddle/jit/dy2static/convert_call_func.py b/python/paddle/jit/dy2static/convert_call_func.py index 2a3a56e2720..54734a62341 100644 --- a/python/paddle/jit/dy2static/convert_call_func.py +++ b/python/paddle/jit/dy2static/convert_call_func.py @@ -288,7 +288,7 @@ def convert_call(func): # If func is not in __globals__, it does not need to be transformed # because it has been transformed before. converted_call = None - except (IOError, OSError): + except OSError: # NOTE: # If func has been decorated, its source code can not be get # so that it can not be transformed to static function. @@ -297,7 +297,7 @@ def convert_call(func): try: converted_call = convert_to_static(func) func_self = getattr(func, '__self__', None) - except (IOError, OSError): + except OSError: # NOTE: func may have been decorated. converted_call = None @@ -313,7 +313,7 @@ def convert_call(func): # So descriptor mechanism is used to bound `self` instance on function to # keep it as bound method. func.forward = forward_func.__get__(func) - except (IOError, OSError, TypeError): + except (OSError, TypeError): # NOTE: func.forward may have been decorated. func_self = None if func_self else func_self converted_call = func @@ -322,7 +322,7 @@ def convert_call(func): call_func = func.__class__.__call__ converted_call = convert_to_static(call_func) func_self = func - except (IOError, OSError, TypeError): + except (OSError, TypeError): # NOTE: # If `func` is a class which is being initialized, for example `convert_call(Foo)()`, # it doesn't need to be transformed diff --git a/tools/CrossStackProfiler/CspFileReader.py b/tools/CrossStackProfiler/CspFileReader.py index 17d49485630..db43cc53618 100755 --- a/tools/CrossStackProfiler/CspFileReader.py +++ b/tools/CrossStackProfiler/CspFileReader.py @@ -139,7 +139,7 @@ class FileReader: self._checkArgsKey("dataPath", str) if not os.path.exists(self._dataPath): - raise IOError( + raise OSError( "input data path [%s] not existed!" % (self._dataPath) ) @@ -220,7 +220,7 @@ class FileReader: ) if not os.path.isfile(fileName): - raise IOError("[%s] is not a valid file!" % (fileName)) + raise OSError("[%s] is not a valid file!" % (fileName)) try: prefix_str = fileName.split(sed)[-1] @@ -298,7 +298,7 @@ class FileReader: def getDict(self, name, groupId, gpuId, tmpPath="./tmp"): fileName = self.getFileName(name, groupId, gpuId, tmpPath) if not os.path.isfile(fileName): - raise IOError("[%s] is not existed!" % fileName) + raise OSError("[%s] is not existed!" % fileName) data = {} with open(fileName, "r") as rf: -- GitLab