Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn with DeprecationWarnings when instantiating Parameters with extra positional arguments #921

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion param/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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.",
ParamPendingDeprecationWarning,
ParamDeprecationWarning,
stacklevel=2,
)

Expand Down
4 changes: 2 additions & 2 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -4199,13 +4199,13 @@ def param(self):

#PARAM3_DEPRECATION
@property
@_deprecated(extra_msg="Use `inst.param.watchers` instead.", warning_cat=FutureWarning)
@_deprecated(extra_msg="Use `inst.param.watchers` instead.", warning_cat=_ParamFutureWarning)
def _param_watchers(self):
return self._param__private.watchers

#PARAM3_DEPRECATION
@_param_watchers.setter
@_deprecated(extra_msg="Use `inst.param.watchers = ...` instead.", warning_cat=FutureWarning)
@_deprecated(extra_msg="Use `inst.param.watchers = ...` instead.", warning_cat=_ParamFutureWarning)
def _param_watchers(self, value):
self._param__private.watchers = value

Expand Down
6 changes: 3 additions & 3 deletions tests/testdeprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def specific_filter():
class TestDeprecateParameter:

def test_deprecate_posargs_Parameter(self):
with pytest.raises(param._utils.ParamPendingDeprecationWarning):
with pytest.raises(param._utils.ParamDeprecationWarning):
param.Parameter(1, 'doc')

def test_deprecate_List_class_(self):
Expand Down Expand Up @@ -103,11 +103,11 @@ def test_deprecate_all_equal(self):
param.parameterized.all_equal(1, 1)

def test_deprecate_param_watchers(self):
with pytest.raises(FutureWarning):
with pytest.raises(param._utils.ParamFutureWarning):
param.parameterized.Parameterized()._param_watchers

def test_deprecate_param_watchers_setter(self):
with pytest.raises(FutureWarning):
with pytest.raises(param._utils.ParamFutureWarning):
param.parameterized.Parameterized()._param_watchers = {}

def test_param_error_unsafe_ops_before_initialized(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/testsignatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.ParamPendingDeprecationWarning,
param._utils.ParamDeprecationWarning,
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.ParamPendingDeprecationWarning,
param._utils.ParamDeprecationWarning,
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.ParamPendingDeprecationWarning,
param._utils.ParamDeprecationWarning,
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)
4 changes: 2 additions & 2 deletions tests/testwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def test_watch_watchers_exposed(self):

obj.param.watch(lambda: '', ['a', 'b'])

with pytest.warns(FutureWarning):
with pytest.warns(param._utils.ParamFutureWarning):
pw = obj._param_watchers
assert isinstance(pw, dict)
for pname in ('a', 'b'):
Expand All @@ -667,7 +667,7 @@ def test_watch_watchers_modified(self):

obj.param.watch(accumulator, ['a', 'b'])

with pytest.warns(FutureWarning):
with pytest.warns(param._utils.ParamFutureWarning):
pw = obj._param_watchers
del pw['a']

Expand Down
Loading