PyAPI: remove use of BaseException
BaseException was used as a catch-all in situations where it didn't make sense and where "Exception" is more appropriate based on Python's documentation & error checking tools, `pylint` warns `broad-exception-caught` for e.g. BaseException includes SystemExit, KeyboardInterrupt & GeneratorExit, so unless the intention is to catch calls to `sys.exit(..)`, breaking a out of a loop using Ctrl-C or generator-exit, then it shouldn't be used. Even then, it's preferable to catch those exceptions explicitly.
This commit is contained in:
@@ -144,7 +144,7 @@ def _fake_module(mod_name, mod_path, speedy=True):
|
||||
|
||||
try:
|
||||
ast_data = ast.parse(data, filename=mod_path)
|
||||
except BaseException:
|
||||
except Exception:
|
||||
print("Syntax error 'ast.parse' can't read:", repr(mod_path))
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
@@ -369,7 +369,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
||||
# in most cases the caller should 'check()' first.
|
||||
try:
|
||||
mod.unregister()
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
print("Exception in module unregister():", (mod_file or module_name))
|
||||
handle_error(ex)
|
||||
return None
|
||||
@@ -382,7 +382,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
||||
|
||||
try:
|
||||
importlib.reload(mod)
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
handle_error(ex)
|
||||
del sys.modules[module_name]
|
||||
return None
|
||||
@@ -420,7 +420,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
||||
)
|
||||
mod.__time__ = os.path.getmtime(mod_file)
|
||||
mod.__addon_enabled__ = False
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
# If the add-on doesn't exist, don't print full trace-back because the back-trace is in this case
|
||||
# is verbose without any useful details. A missing path is better communicated in a short message.
|
||||
# Account for `ImportError` & `ModuleNotFoundError`.
|
||||
@@ -486,7 +486,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
|
||||
# 3) Try run the modules register function.
|
||||
try:
|
||||
mod.register()
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
print("Exception in module register():", (mod_file or module_name))
|
||||
handle_error(ex)
|
||||
del sys.modules[module_name]
|
||||
@@ -535,7 +535,7 @@ def disable(module_name, *, default_set=False, handle_error=None):
|
||||
|
||||
try:
|
||||
mod.unregister()
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
mod_path = getattr(mod, "__file__", module_name)
|
||||
print("Exception in module unregister():", repr(mod_path))
|
||||
del mod_path
|
||||
@@ -1201,7 +1201,7 @@ def _bl_info_from_extension(mod_name, mod_path):
|
||||
except FileNotFoundError:
|
||||
print("Warning: add-on missing manifest, this can cause poor performance!:", repr(filepath_toml))
|
||||
return None, filepath_toml
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
print("Error:", str(ex), "in", filepath_toml)
|
||||
return None, filepath_toml
|
||||
|
||||
@@ -1225,7 +1225,7 @@ def _bl_info_from_extension(mod_name, mod_path):
|
||||
(int if i < 2 else _version_int_left_digits)(x)
|
||||
for i, x in enumerate(value.split(".", 2))
|
||||
)
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
print("Error: \"version\" is not a semantic version (X.Y.Z) in ", filepath_toml, str(ex))
|
||||
return None, filepath_toml
|
||||
bl_info["version"] = value
|
||||
@@ -1238,7 +1238,7 @@ def _bl_info_from_extension(mod_name, mod_path):
|
||||
return None, filepath_toml
|
||||
try:
|
||||
value = tuple(int(x) for x in value.split("."))
|
||||
except BaseException as ex:
|
||||
except Exception as ex:
|
||||
print("Error:", str(ex), "in \"blender_version_min\"", filepath_toml)
|
||||
return None, filepath_toml
|
||||
bl_info["blender"] = value
|
||||
@@ -1410,7 +1410,7 @@ def _extension_dirpath_from_handle():
|
||||
# meddle with the modules.
|
||||
try:
|
||||
dirpath = module.__path__[0]
|
||||
except BaseException:
|
||||
except Exception:
|
||||
dirpath = ""
|
||||
repos_info[module_id] = dirpath
|
||||
return repos_info
|
||||
|
||||
Reference in New Issue
Block a user