From 3385679bbb26c0ed92452d39652c54e6f315188d Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Tue, 13 Feb 2024 18:31:48 +0100 Subject: [PATCH 1/3] 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 From 1bf9617f946f8b85cad904d0e07004084078ad62 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Wed, 14 Feb 2024 14:04:18 +0100 Subject: [PATCH 2/3] remove wrapper module. --- modopt/base/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modopt/base/__init__.py b/modopt/base/__init__.py index 1c0c8b2c..88424bae 100644 --- a/modopt/base/__init__.py +++ b/modopt/base/__init__.py @@ -9,4 +9,4 @@ """ -__all__ = ['np_adjust', 'transform', 'types', 'wrappers', 'observable'] +__all__ = ['np_adjust', 'transform', 'types', 'observable'] From 557023e20ea4cb1cc084f1a65c2652e5b4ceed13 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 16 Feb 2024 17:56:46 +0100 Subject: [PATCH 3/3] cleanup --- modopt/base/types.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/modopt/base/types.py b/modopt/base/types.py index e9212e12..16e06f15 100644 --- a/modopt/base/types.py +++ b/modopt/base/types.py @@ -12,7 +12,7 @@ from modopt.interface.errors import warn -def check_callable(input_obj, add_agrs=True): +def check_callable(input_obj): """Check input object is callable. This method checks if the input operator is a callable funciton and @@ -23,23 +23,11 @@ def check_callable(input_obj, add_agrs=True): ---------- input_obj : callable Callable function - add_agrs : bool, optional - Option to add support for agrs and kwargs (default is ``True``) - - Returns - ------- - function - Function wrapped by ``add_args_kwargs`` Raises ------ TypeError For invalid input type - - See Also - -------- - modopt.base.wrappers.add_args_kwargs : wrapper used - """ if not callable(input_obj): raise TypeError('The input object must be a callable function.')