From 060337d059ecab82160be74339bfdd978ea456ab Mon Sep 17 00:00:00 2001 From: Tim Mensinger Date: Wed, 13 Nov 2024 16:23:30 +0100 Subject: [PATCH] Switch back to try-except-pass instead of contextlib.suppress --- src/estimagic/__init__.py | 3 +-- src/optimagic/__init__.py | 4 +--- src/optimagic/optimizers/pygmo_optimizers.py | 5 +++-- src/optimagic/optimizers/tao_optimizers.py | 5 +++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/estimagic/__init__.py b/src/estimagic/__init__.py index 056f823e4..a987f8082 100644 --- a/src/estimagic/__init__.py +++ b/src/estimagic/__init__.py @@ -1,11 +1,10 @@ -import contextlib import warnings from dataclasses import dataclass try: import pdbp # noqa: F401 except ImportError: - contextlib.suppress(Exception) + pass from estimagic import utilities from estimagic.bootstrap import BootstrapResult, bootstrap diff --git a/src/optimagic/__init__.py b/src/optimagic/__init__.py index e1cbd6a3c..a4837ca0a 100644 --- a/src/optimagic/__init__.py +++ b/src/optimagic/__init__.py @@ -1,11 +1,9 @@ from __future__ import annotations -import contextlib - try: import pdbp # noqa: F401 except ImportError: - contextlib.suppress(Exception) + pass from optimagic import constraints, mark, utilities from optimagic.algorithms import algos diff --git a/src/optimagic/optimizers/pygmo_optimizers.py b/src/optimagic/optimizers/pygmo_optimizers.py index e8be80ff6..44e6c7339 100644 --- a/src/optimagic/optimizers/pygmo_optimizers.py +++ b/src/optimagic/optimizers/pygmo_optimizers.py @@ -19,7 +19,6 @@ from __future__ import annotations -import contextlib import warnings from dataclasses import dataclass from typing import Any, List, Literal @@ -48,8 +47,10 @@ STOPPING_MAX_ITERATIONS_GENETIC = 250 -with contextlib.suppress(ImportError): +try: import pygmo as pg +except ImportError: + pass @mark.minimizer( diff --git a/src/optimagic/optimizers/tao_optimizers.py b/src/optimagic/optimizers/tao_optimizers.py index 508c7f444..8ea2401b5 100644 --- a/src/optimagic/optimizers/tao_optimizers.py +++ b/src/optimagic/optimizers/tao_optimizers.py @@ -1,6 +1,5 @@ """This module implements the POUNDERs algorithm.""" -import contextlib import functools from dataclasses import dataclass @@ -23,8 +22,10 @@ from optimagic.typing import AggregationLevel, NonNegativeFloat, PositiveInt from optimagic.utilities import calculate_trustregion_initial_radius -with contextlib.suppress(ImportError): +try: from petsc4py import PETSc +except ImportError: + pass @mark.minimizer(