Skip to content

Commit

Permalink
Switch back to try-except-pass instead of contextlib.suppress
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens committed Nov 13, 2024
1 parent 09f4719 commit 060337d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/estimagic/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/optimagic/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/optimagic/optimizers/pygmo_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from __future__ import annotations

import contextlib
import warnings
from dataclasses import dataclass
from typing import Any, List, Literal
Expand Down Expand Up @@ -48,8 +47,10 @@

STOPPING_MAX_ITERATIONS_GENETIC = 250

with contextlib.suppress(ImportError):
try:
import pygmo as pg
except ImportError:
pass

Check warning on line 53 in src/optimagic/optimizers/pygmo_optimizers.py

View check run for this annotation

Codecov / codecov/patch

src/optimagic/optimizers/pygmo_optimizers.py#L52-L53

Added lines #L52 - L53 were not covered by tests


@mark.minimizer(
Expand Down
5 changes: 3 additions & 2 deletions src/optimagic/optimizers/tao_optimizers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module implements the POUNDERs algorithm."""

import contextlib
import functools
from dataclasses import dataclass

Expand All @@ -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

Check warning on line 28 in src/optimagic/optimizers/tao_optimizers.py

View check run for this annotation

Codecov / codecov/patch

src/optimagic/optimizers/tao_optimizers.py#L27-L28

Added lines #L27 - L28 were not covered by tests


@mark.minimizer(
Expand Down

0 comments on commit 060337d

Please sign in to comment.