def conserve_mpmath_dps(func):
 import functools
 import mpmath
 def func_wrapper(*args, **kwargs):
  dps = mpmath.mp.dps
  try:
   return func(*args, **kwargs)
  finally:
   mpmath.mp.dps = dps
 func_wrapper = functools.update_wrapper(func_wrapper, func)
 return func_wrapper

def conserve_mpmath_dps ( func ) : import functools import mpmath def func_wrapper ( * args , ** kwargs ) : dps = mpmath . mp . dps try : return func ( * args , ** kwargs ) finally : mpmath . mp . dps = dps func_wrapper = functools . update_wrapper ( func_wrapper , func ) return func_wrapper
after the function finishes .