未验证 提交 8c888eea 编写于 作者: I Infinity_lee 提交者: GitHub

[CodeStyle][UP024] Replace aliased errors with OSError (#52024)

上级 b166581a
...@@ -318,7 +318,7 @@ def cvt_to_device(x, dev_id, blocking=True): ...@@ -318,7 +318,7 @@ def cvt_to_device(x, dev_id, blocking=True):
elif paddle.is_compiled_with_xpu(): elif paddle.is_compiled_with_xpu():
place = paddle.XPUPlace(dev_id) place = paddle.XPUPlace(dev_id)
else: else:
raise EnvironmentError( raise OSError(
"Only supported compiled paddle with gpu/rocm, npu and xpu , but current verison is compiled with cpu." "Only supported compiled paddle with gpu/rocm, npu and xpu , but current verison is compiled with cpu."
) )
return x._copy_to(place, blocking) return x._copy_to(place, blocking)
...@@ -288,7 +288,7 @@ def convert_call(func): ...@@ -288,7 +288,7 @@ def convert_call(func):
# If func is not in __globals__, it does not need to be transformed # If func is not in __globals__, it does not need to be transformed
# because it has been transformed before. # because it has been transformed before.
converted_call = None converted_call = None
except (IOError, OSError): except OSError:
# NOTE: # NOTE:
# If func has been decorated, its source code can not be get # If func has been decorated, its source code can not be get
# so that it can not be transformed to static function. # so that it can not be transformed to static function.
...@@ -297,7 +297,7 @@ def convert_call(func): ...@@ -297,7 +297,7 @@ def convert_call(func):
try: try:
converted_call = convert_to_static(func) converted_call = convert_to_static(func)
func_self = getattr(func, '__self__', None) func_self = getattr(func, '__self__', None)
except (IOError, OSError): except OSError:
# NOTE: func may have been decorated. # NOTE: func may have been decorated.
converted_call = None converted_call = None
...@@ -313,7 +313,7 @@ def convert_call(func): ...@@ -313,7 +313,7 @@ def convert_call(func):
# So descriptor mechanism is used to bound `self` instance on function to # So descriptor mechanism is used to bound `self` instance on function to
# keep it as bound method. # keep it as bound method.
func.forward = forward_func.__get__(func) func.forward = forward_func.__get__(func)
except (IOError, OSError, TypeError): except (OSError, TypeError):
# NOTE: func.forward may have been decorated. # NOTE: func.forward may have been decorated.
func_self = None if func_self else func_self func_self = None if func_self else func_self
converted_call = func converted_call = func
...@@ -322,7 +322,7 @@ def convert_call(func): ...@@ -322,7 +322,7 @@ def convert_call(func):
call_func = func.__class__.__call__ call_func = func.__class__.__call__
converted_call = convert_to_static(call_func) converted_call = convert_to_static(call_func)
func_self = func func_self = func
except (IOError, OSError, TypeError): except (OSError, TypeError):
# NOTE: # NOTE:
# If `func` is a class which is being initialized, for example `convert_call(Foo)()`, # If `func` is a class which is being initialized, for example `convert_call(Foo)()`,
# it doesn't need to be transformed # it doesn't need to be transformed
......
...@@ -139,7 +139,7 @@ class FileReader: ...@@ -139,7 +139,7 @@ class FileReader:
self._checkArgsKey("dataPath", str) self._checkArgsKey("dataPath", str)
if not os.path.exists(self._dataPath): if not os.path.exists(self._dataPath):
raise IOError( raise OSError(
"input data path [%s] not existed!" % (self._dataPath) "input data path [%s] not existed!" % (self._dataPath)
) )
...@@ -220,7 +220,7 @@ class FileReader: ...@@ -220,7 +220,7 @@ class FileReader:
) )
if not os.path.isfile(fileName): 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: try:
prefix_str = fileName.split(sed)[-1] prefix_str = fileName.split(sed)[-1]
...@@ -298,7 +298,7 @@ class FileReader: ...@@ -298,7 +298,7 @@ class FileReader:
def getDict(self, name, groupId, gpuId, tmpPath="./tmp"): def getDict(self, name, groupId, gpuId, tmpPath="./tmp"):
fileName = self.getFileName(name, groupId, gpuId, tmpPath) fileName = self.getFileName(name, groupId, gpuId, tmpPath)
if not os.path.isfile(fileName): if not os.path.isfile(fileName):
raise IOError("[%s] is not existed!" % fileName) raise OSError("[%s] is not existed!" % fileName)
data = {} data = {}
with open(fileName, "r") as rf: with open(fileName, "r") as rf:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册