Skip to content

Commit

Permalink
Remove bare except and replace == None by is None.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxJPRey committed Dec 26, 2024
1 parent a78f5e3 commit a744bb7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/app_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/embedding/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/embedding/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/logger/windows_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")


Expand Down
4 changes: 1 addition & 3 deletions src/ansys/mechanical/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a744bb7

Please sign in to comment.