From 1e7ea4a1c29229475c3b84d23cca0b493b742614 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 4 May 2023 07:59:54 -0700 Subject: [PATCH] inline missing class --- go_benchmark_functions/go_benchmark.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/go_benchmark_functions/go_benchmark.py b/go_benchmark_functions/go_benchmark.py index 0ee1d3c..8fb3802 100644 --- a/go_benchmark_functions/go_benchmark.py +++ b/go_benchmark_functions/go_benchmark.py @@ -2,7 +2,22 @@ import numpy as np from numpy import abs, asarray -from ..common import safe_import + +class safe_import: + def __enter__(self): + self.error = False + return self + + def __exit__(self, type_, value, traceback): + if type_ is not None: + self.error = True + suppress = not ( + os.getenv("SCIPY_ALLOW_BENCH_IMPORT_ERRORS", "1").lower() + in ("0", "false") + or not issubclass(type_, ImportError) + ) + return suppress + with safe_import(): from scipy.special import factorial