From 3ec88f917f4f1761475efe67cf220d15bb1c4e38 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Sun, 24 Jul 2022 20:07:31 +0800 Subject: [PATCH] fix(docs): fix sphinx document build Signed-off-by: Xuehai Pan --- nvitop/core/libcuda.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nvitop/core/libcuda.py b/nvitop/core/libcuda.py index f93a3d4..0428e42 100644 --- a/nvitop/core/libcuda.py +++ b/nvitop/core/libcuda.py @@ -215,7 +215,7 @@ class CUDAError(Exception): _errcode_to_name = {} def __new__(cls, value: int) -> 'CUDAError': - """Maps value to a proper subclass of :class:`CUError`.""" + """Maps value to a proper subclass of :class:`CUDAError`.""" if cls is CUDAError: # pylint: disable=self-cls-assignment @@ -251,7 +251,7 @@ class CUDAError(Exception): def cudaExceptionClass(cudaErrorCode: int) -> _Type[CUDAError]: - """Maps value to a proper subclass of :class:`CUError`. + """Maps value to a proper subclass of :class:`CUDAError`. Raises: ValueError: If the error code is not valid. @@ -273,8 +273,6 @@ def _extract_cuda_errors_as_classes() -> None: e.g. :data:`CUDA_ERROR_INVALID_VALUE` will be turned into :class:`CUDAError_InvalidValue`. """ - import functools # pylint: disable=import-outside-toplevel - this_module = _sys.modules[__name__] cuda_error_names = [x for x in dir(this_module) if x.startswith('CUDA_ERROR_')] for err_name in cuda_error_names: @@ -283,12 +281,15 @@ def _extract_cuda_errors_as_classes() -> None: class_name = 'CUDAError_{}'.format(pascal_case) err_val = getattr(this_module, err_name) + def gen_new(value): + def new(cls): + obj = CUDAError.__new__(cls, value) + return obj + + return new + # pylint: disable=protected-access - new_error_class = type( - class_name, - (CUDAError,), - {'__new__': functools.partial(CUDAError.__new__, value=err_val)}, - ) + new_error_class = type(class_name, (CUDAError,), {'__new__': gen_new(err_val)}) new_error_class.__module__ = __name__ if err_val in CUDAError._errcode_to_string: new_error_class.__doc__ = 'CUDA Error: {} Code: :data:`{}` ({}).'.format(