From 3385679bbb26c0ed92452d39652c54e6f315188d Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 13 Feb 2024 18:31:48 +0100 Subject: [PATCH] refactor: remove add_args_kwargs. This is 1) expensive 2) dangerous 3) source of bug. --- modopt/base/types.py | 6 ----- modopt/base/wrappers.py | 49 ----------------------------------------- 2 files changed, 55 deletions(-) delete mode 100644 modopt/base/wrappers.py diff --git a/modopt/base/types.py b/modopt/base/types.py index 88051675..e9212e12 100644 --- a/modopt/base/types.py +++ b/modopt/base/types.py @@ -9,8 +9,6 @@ """ import numpy as np - -from modopt.base.wrappers import add_args_kwargs from modopt.interface.errors import warn @@ -45,10 +43,6 @@ def check_callable(input_obj, add_agrs=True): """ if not callable(input_obj): raise TypeError('The input object must be a callable function.') - - if add_agrs: - input_obj = add_args_kwargs(input_obj) - return input_obj diff --git a/modopt/base/wrappers.py b/modopt/base/wrappers.py deleted file mode 100644 index baedb891..00000000 --- a/modopt/base/wrappers.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- - -"""WRAPPERS. - -This module contains wrappers for adding additional features to functions. - -:Author: Samuel Farrens - -""" - -from functools import wraps -from inspect import getfullargspec as argspec - - -def add_args_kwargs(func): - """Add args and kwargs. - - This wrapper adds support for additional arguments and keyword arguments to - any callable function. - - Parameters - ---------- - func : callable - Callable function - - Returns - ------- - callable - wrapper - - """ - @wraps(func) - def wrapper(*args, **kwargs): - - props = argspec(func) - - # if 'args' not in props: - if isinstance(props[1], type(None)): - args = args[:len(props[0])] - - if ( - (not isinstance(props[2], type(None))) - or (not isinstance(props[3], type(None))) - ): - return func(*args, **kwargs) - - return func(*args) - - return wrapper