diff --git a/param/_utils.py b/param/_utils.py index 25f3a5fd..9f918ab9 100644 --- a/param/_utils.py +++ b/param/_utils.py @@ -106,7 +106,7 @@ def inner(*args, **kwargs): f"Passing '{extra_args}' as positional argument(s) to 'param.{name}' " "has been deprecated since Param 2.0.0 and will raise an error in a future version, " "please pass them as keyword arguments.", - ParamDeprecationWarning, + ParamFutureWarning, stacklevel=2, ) @@ -306,7 +306,7 @@ def _produce_value(value_obj): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def produce_value(value_obj): """ A helper function that produces an actual parameter from a stored @@ -319,7 +319,7 @@ def produce_value(value_obj): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def as_unicode(obj): """ Safely casts any object to unicode including regular string @@ -331,7 +331,7 @@ def as_unicode(obj): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def is_ordered_dict(d): """ Predicate checking for ordered dictionaries. OrderedDict is always @@ -362,7 +362,7 @@ def _hashable(x): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def hashable(x): """ Return a hashable version of the given object x, with lists and @@ -411,7 +411,7 @@ def _named_objs(objlist, namesdict=None): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def named_objs(objlist, namesdict=None): """ Given a list of objects, returns a dictionary mapping from @@ -549,7 +549,7 @@ def _abbreviate_paths(pathspec,named_paths): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=ParamFutureWarning) def abbreviate_paths(pathspec,named_paths): """ Given a dict of (pathname,path) pairs, removes any prefix shared by all pathnames. diff --git a/param/parameterized.py b/param/parameterized.py index 090e9b9a..9d154d02 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -36,7 +36,6 @@ from . import serializer from ._utils import ( DEFAULT_SIGNATURE, - ParamDeprecationWarning as _ParamDeprecationWarning, ParamFutureWarning as _ParamFutureWarning, Skip, _deprecated, @@ -286,7 +285,7 @@ def _batch_call_watchers(parameterized, enable=True, run=True): # PARAM3_DEPRECATION -@_deprecated(extra_msg="Use instead `batch_call_watchers`.") +@_deprecated(extra_msg="Use instead `batch_call_watchers`.", warning_cat=_ParamFutureWarning) @contextmanager def batch_watch(parameterized, enable=True, run=True): with _batch_call_watchers(parameterized, enable, run): @@ -395,7 +394,7 @@ def get_occupied_slots(instance): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=_ParamFutureWarning) def all_equal(arg1,arg2): """ Return a single boolean for arg1==arg2, even for numpy arrays @@ -422,7 +421,7 @@ def all_equal(arg1,arg2): # (https://docs.python.org/3/reference/datamodel.html#customizing-class-creation) # # Code from six (https://bitbucket.org/gutworth/six; version 1.4.1). -@_deprecated() +@_deprecated(warning_cat=_ParamFutureWarning) def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass. @@ -544,7 +543,7 @@ def recursive_repr(fillvalue='...'): """ warnings.warn( 'recursive_repr has been deprecated and will be removed in a future version.', - category=_ParamDeprecationWarning, + category=_ParamFutureWarning, stacklevel=2, ) return _recursive_repr(fillvalue=fillvalue) @@ -1483,7 +1482,7 @@ def __set__(self, obj, val): # PARAM3_DEPRECATION warnings.warn( 'Number.set_hook has been deprecated.', - category=_ParamDeprecationWarning, + category=_ParamFutureWarning, stacklevel=6, ) @@ -2222,7 +2221,7 @@ def _repr_html_(self_, open=True): # Classmethods # PARAM3_DEPRECATION - @_deprecated(extra_msg="""Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`""") + @_deprecated(extra_msg="""Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`""", warning_cat=_ParamFutureWarning) def print_param_defaults(self_): """Print the default values of all cls's Parameters. @@ -2235,7 +2234,7 @@ def print_param_defaults(self_): print(cls.__name__+'.'+key+ '='+ repr(val.default)) # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `p.param.default =`") + @_deprecated(extra_msg="Use instead `p.param.default =`", warning_cat=_ParamFutureWarning) def set_default(self_,param_name,value): """ Set the default value of param_name. @@ -2266,7 +2265,7 @@ def add_parameter(self_, param_name, param_obj): cls._param__private.params.clear() # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.add_parameter`") + @_deprecated(extra_msg="Use instead `.param.add_parameter`", warning_cat=_ParamFutureWarning) def _add_parameter(self_,param_name, param_obj): """Add a new Parameter object into this object's class. @@ -2275,7 +2274,7 @@ def _add_parameter(self_,param_name, param_obj): return self_.add_parameter(param_name, param_obj) # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.values()` or `.param['param']`") + @_deprecated(extra_msg="Use instead `.param.values()` or `.param['param']`", warning_cat=_ParamFutureWarning) def params(self_, parameter_name=None): """ Return the Parameters of this class as the @@ -2358,7 +2357,7 @@ def _update(self_, arg=Undefined, /, **kwargs): return restore # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.update`") + @_deprecated(extra_msg="Use instead `.param.update`", warning_cat=_ParamFutureWarning) def set_param(self_, *args,**kwargs): """ For each param=value keyword argument, sets the corresponding @@ -2621,7 +2620,7 @@ def schema(self_, safe=False, subset=None, mode='json'): @_deprecated(extra_msg=""" Use `.param.values().items()` instead (or `.param.values()` for the common case of `dict(....param.get_param_values())`) - """) + """, warning_cat=_ParamFutureWarning) def get_param_values(self_, onlychanged=False): """ Return a list of name,value pairs for all Parameters of this @@ -2763,7 +2762,7 @@ def method_dependencies(self_, name, intermediate=False): self_.self, deps, dynamic, intermediate=intermediate) # PARAM3_DEPRECATION - @_deprecated(extra_msg='Use instead `.param.method_dependencies`') + @_deprecated(extra_msg='Use instead `.param.method_dependencies`', warning_cat=_ParamFutureWarning) def params_depended_on(self_, *args, **kwargs): """ Given the name of a method, returns a PInfo object for each dependency @@ -3008,7 +3007,7 @@ def watch_values(self_, fn, parameter_names, what='value', onlychanged=True, que # Instance methods # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `{k:v.default for k,v in p.param.objects().items()}`") + @_deprecated(extra_msg="Use instead `{k:v.default for k,v in p.param.objects().items()}`", warning_cat=_ParamFutureWarning) def defaults(self_): """ Return {parameter_name:parameter.default} for all non-constant @@ -3049,7 +3048,7 @@ def __db_print(self_,level,msg,*args,**kw): get_logger(name=self_or_cls.name).log(level, msg, *args, **kw) # PARAM3_DEPRECATION - @_deprecated(extra_msg="""Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`""") + @_deprecated(extra_msg="""Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`""", warning_cat=_ParamFutureWarning) def print_param_values(self_): """Print the values of all this object's Parameters. @@ -3071,7 +3070,7 @@ def warning(self_, msg,*args,**kw): self_.log(WARNING, msg, *args, **kw) # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.log(param.MESSAGE, ...)`") + @_deprecated(extra_msg="Use instead `.param.log(param.MESSAGE, ...)`", warning_cat=_ParamFutureWarning) def message(self_,msg,*args,**kw): """ Print msg merged with args as a message. @@ -3084,7 +3083,7 @@ def message(self_,msg,*args,**kw): self_.__db_print(INFO,msg,*args,**kw) # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.log(param.VERBOSE, ...)`") + @_deprecated(extra_msg="Use instead `.param.log(param.VERBOSE, ...)`", warning_cat=_ParamFutureWarning) def verbose(self_,msg,*args,**kw): """ Print msg merged with args as a verbose message. @@ -3097,7 +3096,7 @@ def verbose(self_,msg,*args,**kw): self_.__db_print(VERBOSE,msg,*args,**kw) # PARAM3_DEPRECATION - @_deprecated(extra_msg="Use instead `.param.log(param.DEBUG, ...)`") + @_deprecated(extra_msg="Use instead `.param.log(param.DEBUG, ...)`", warning_cat=_ParamFutureWarning) def debug(self_,msg,*args,**kw): """ Print msg merged with args as a debugging statement. @@ -4511,7 +4510,7 @@ class overridable_property: def __init__(self, fget=None, fset=None, fdel=None, doc=None): warnings.warn( message="overridable_property has been deprecated.", - category=_ParamDeprecationWarning, + category=_ParamFutureWarning, stacklevel=2, ) self.fget = fget diff --git a/param/parameters.py b/param/parameters.py index fe327279..a00813b0 100644 --- a/param/parameters.py +++ b/param/parameters.py @@ -39,7 +39,7 @@ _int_types, _identity_hook ) from ._utils import ( - ParamDeprecationWarning as _ParamDeprecationWarning, + ParamFutureWarning as _ParamFutureWarning, _deprecate_positional_args, _deprecated, _validate_error_prefix, @@ -2497,7 +2497,7 @@ def __init__(self, default=Undefined, *, class_=Undefined, item_type=Undefined, # PARAM3_DEPRECATION warnings.warn( message="The 'class_' attribute on 'List' is deprecated. Use instead 'item_type'", - category=_ParamDeprecationWarning, + category=_ParamFutureWarning, stacklevel=3, ) if item_type is not Undefined and class_ is not Undefined: @@ -2658,7 +2658,7 @@ def __call__(self, path, **params): # PARAM3_DEPRECATION -@_deprecated() +@_deprecated(warning_cat=_ParamFutureWarning) class normalize_path(ParameterizedFunction): """ Convert a UNIX-style path to the current OS's format, diff --git a/tests/testdeprecations.py b/tests/testdeprecations.py index 3253b358..1f9bf4c8 100644 --- a/tests/testdeprecations.py +++ b/tests/testdeprecations.py @@ -21,11 +21,11 @@ def specific_filter(): class TestDeprecateParameter: def test_deprecate_posargs_Parameter(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.Parameter(1, 'doc') def test_deprecate_List_class_(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.List(class_=int) def test_deprecate_Number_set_hook(self): @@ -33,45 +33,45 @@ class P(param.Parameterized): n = param.Number(set_hook=lambda obj, val: val) p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.n = 1 class TestDeprecateInitModule: def test_deprecate_as_unicode(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.as_unicode(1) def test_deprecate_is_ordered_dict(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.is_ordered_dict(dict()) def test_deprecate_produce_value(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.produce_value(1) def test_deprecate_hasbable(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.hashable('s') def test_deprecate_named_objs(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.named_objs(dict()) def test_deprecate_normalize_path(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.normalize_path() def test_deprecate_abbreviate_path(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.abbreviate_paths() class TestDeprecateParameterizedModule: def test_deprecate_overridable_property(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): class Foo: def _x(self): pass x = param.parameterized.overridable_property(_x) @@ -82,23 +82,23 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): with param.parameterized.batch_watch(p): pass def test_deprecate_add_metaclass(self): class MC(type): pass - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): @param.parameterized.add_metaclass(MC) class Base: pass def test_deprecate_recursive_repr(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.parameterized.recursive_repr(lambda: '') def test_deprecate_all_equal(self): - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): param.parameterized.all_equal(1, 1) @@ -110,21 +110,21 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.print_param_defaults() def test_deprecate_set_default(self): class P(param.Parameterized): x = param.Parameter() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): P.param.set_default('x', 1) def test_deprecate__add_parameter(self): class P(param.Parameterized): x = param.Parameter() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): P.param._add_parameter('y', param.Parameter()) def test_deprecate_params(self): @@ -133,7 +133,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.params() def test_deprecate_set_param(self): @@ -142,7 +142,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.set_param('x', 1) def test_deprecate_get_param_values(self): @@ -151,7 +151,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.get_param_values() def test_deprecate_params_depended_on(self): @@ -160,7 +160,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.params_depended_on() def test_deprecate_defaults(self): @@ -169,7 +169,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.defaults() def test_deprecate_print_param_values(self): @@ -178,7 +178,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.print_param_values() def test_deprecate_message(self): @@ -187,7 +187,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.message('test') def test_deprecate_verbose(self): @@ -196,7 +196,7 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.verbose('test') def test_deprecate_debug(self): @@ -205,5 +205,5 @@ class P(param.Parameterized): p = P() - with pytest.raises(param._utils.ParamDeprecationWarning): + with pytest.raises(param._utils.ParamFutureWarning): p.param.debug('test') diff --git a/tests/testsignatures.py b/tests/testsignatures.py index 2f56ce8a..9ce75528 100644 --- a/tests/testsignatures.py +++ b/tests/testsignatures.py @@ -97,17 +97,17 @@ def test_signature_position_keywords(): def test_signature_warning_by_position(): # Simple test as it's tricky to automatically test all the Parameters with pytest.warns( - param._utils.ParamDeprecationWarning, + param._utils.ParamFutureWarning, match=r"Passing 'objects' as positional argument\(s\) to 'param.Selector' has been deprecated since Param 2.0.0 and will raise an error in a future version, please pass them as keyword arguments" ): param.Selector([0, 1]) # objects with pytest.warns( - param._utils.ParamDeprecationWarning, + param._utils.ParamFutureWarning, match=r"Passing 'class_' as positional argument\(s\) to 'param.ClassSelector' has been deprecated since Param 2.0.0 and will raise an error in a future version, please pass them as keyword arguments" ): param.ClassSelector(int) # class_ with pytest.warns( - param._utils.ParamDeprecationWarning, + param._utils.ParamFutureWarning, match=r"Passing 'bounds, softbounds' as positional argument\(s\) to 'param.Number' has been deprecated since Param 2.0.0 and will raise an error in a future version, please pass them as keyword arguments" ): param.Number(1, (0, 2), (0, 2)) # default (OK), bounds (not OK), softbounds (not OK)