Skip to content

Commit

Permalink
promote deprecation warnings to future warnings (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt authored Nov 26, 2024
1 parent 08dd44d commit b964a5d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 59 deletions.
14 changes: 7 additions & 7 deletions param/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 18 additions & 19 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from . import serializer
from ._utils import (
DEFAULT_SIGNATURE,
ParamDeprecationWarning as _ParamDeprecationWarning,
ParamFutureWarning as _ParamFutureWarning,
Skip,
_deprecated,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions param/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
_int_types, _identity_hook
)
from ._utils import (
ParamDeprecationWarning as _ParamDeprecationWarning,
ParamFutureWarning as _ParamFutureWarning,
_deprecate_positional_args,
_deprecated,
_validate_error_prefix,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit b964a5d

Please sign in to comment.