From a744bb772dcf85e2b8fb8d603b19462478fff84e Mon Sep 17 00:00:00 2001 From: Maxime Rey Date: Thu, 26 Dec 2024 11:59:25 +0100 Subject: [PATCH] Remove bare except and replace == None by is None. --- src/ansys/mechanical/core/embedding/app_libraries.py | 2 +- src/ansys/mechanical/core/embedding/initializer.py | 4 ++-- src/ansys/mechanical/core/embedding/logger/__init__.py | 4 ++-- src/ansys/mechanical/core/embedding/logger/windows_api.py | 2 +- src/ansys/mechanical/core/mechanical.py | 4 +--- tests/conftest.py | 6 +++--- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/app_libraries.py b/src/ansys/mechanical/core/embedding/app_libraries.py index eb8bff5df..69a75e88c 100644 --- a/src/ansys/mechanical/core/embedding/app_libraries.py +++ b/src/ansys/mechanical/core/embedding/app_libraries.py @@ -74,7 +74,7 @@ def add_mechanical_python_libraries(app_or_version): elif isinstance(app_or_version, App): installdir.append(os.environ[f"AWP_ROOT{app_or_version.version}"]) else: - raise ValueError(f"Invalid input: expected an integer (version) or an instance of App().") + raise ValueError("Invalid input: expected an integer (version) or an instance of App().") location = os.path.join(installdir[0], "Addins", "ACT", "libraries", "Mechanical") sys.path.append(location) diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index 05c1ead6e..10cd673bb 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -138,7 +138,7 @@ def __is_lib_loaded(libname: str): # pragma: no cover RTLD_NOLOAD = 4 try: ctypes.CDLL(libname, RTLD_NOLOAD) - except: + except OSError: return False return True @@ -174,7 +174,7 @@ def initialize(version: int = None): ) return - if version == None: + if version is None: version = _get_latest_default_version() version = __check_for_supported_version(version=version) diff --git a/src/ansys/mechanical/core/embedding/logger/__init__.py b/src/ansys/mechanical/core/embedding/logger/__init__.py index bf8133d48..c96922631 100644 --- a/src/ansys/mechanical/core/embedding/logger/__init__.py +++ b/src/ansys/mechanical/core/embedding/logger/__init__.py @@ -144,14 +144,14 @@ def set_log_level(cls, level: int) -> None: @classmethod def set_log_directory(cls, value: str) -> None: """Configure logging to write to a directory.""" - if value == None: + if value is None: return _get_backend().set_directory(value) @classmethod def set_log_base_directory(cls, directory: str) -> None: """Configure logging to write in a time-stamped subfolder in this directory.""" - if directory == None: + if directory is None: return _get_backend().set_base_directory(directory) diff --git a/src/ansys/mechanical/core/embedding/logger/windows_api.py b/src/ansys/mechanical/core/embedding/logger/windows_api.py index 8e5bcbc3a..a301b42e0 100644 --- a/src/ansys/mechanical/core/embedding/logger/windows_api.py +++ b/src/ansys/mechanical/core/embedding/logger/windows_api.py @@ -41,7 +41,7 @@ def _get_logger(): import Ansys return Ansys.Common.WB1ManagedUtils.Logger - except: + except (ImportError, RuntimeError): raise Exception("Logging cannot be used until after Mechanical embedding is initialized.") diff --git a/src/ansys/mechanical/core/mechanical.py b/src/ansys/mechanical/core/mechanical.py index 55c7bc5fd..cbfe77003 100644 --- a/src/ansys/mechanical/core/mechanical.py +++ b/src/ansys/mechanical/core/mechanical.py @@ -480,9 +480,8 @@ def version(self) -> str: >>> mechanical.version '242' - """ - if self._version == None: + if self._version is None: try: self._disable_logging = True script = ( @@ -537,7 +536,6 @@ def _multi_connect(self, n_attempts=5, timeout=60): timeout : float, optional Maximum allowable time in seconds for establishing a connection. The default is ``60``. - """ # This prevents a single failed connection from blocking other attempts connected = False diff --git a/tests/conftest.py b/tests/conftest.py index 74de05054..bffde69ad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -167,7 +167,7 @@ def embedded_app(pytestconfig, request): @pytest.fixture(autouse=True) def mke_app_reset(request): global EMBEDDED_APP - if EMBEDDED_APP == None: + if EMBEDDED_APP is None: # embedded app was not started - no need to do anything return terminal_reporter = request.config.pluginmanager.getplugin("terminalreporter") @@ -178,7 +178,7 @@ def mke_app_reset(request): _CHECK_PROCESS_RETURN_CODE = os.name == "nt" -# set to true if you want to see all the subprocess stdout/stderr +# set to True if you want to see all the subprocess stdout/stderr _PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE = False @@ -374,7 +374,7 @@ def mechanical_pool(): def pytest_addoption(parser): mechanical_path = atp.get_mechanical_path(False) - if mechanical_path == None: + if mechanical_path is None: parser.addoption("--ansys-version", default="242") else: mechanical_version = atp.version_from_path("mechanical", mechanical_path)