diff --git a/doc/user_guide/Serialization_and_Persistence.ipynb b/doc/user_guide/Serialization_and_Persistence.ipynb index a37d0e202..7e57a7339 100644 --- a/doc/user_guide/Serialization_and_Persistence.ipynb +++ b/doc/user_guide/Serialization_and_Persistence.ipynb @@ -143,7 +143,7 @@ "\n", "1. **Callable parameter values**: If you provide any `param.Callable`, `param.Hooklist`, or other parameters that can accept callable objects to your users, you will need to warn them that none of those can be set to unnamed (lambda) functions or to one-off functions defined in the main namespace if they want to use pickling. Of course, you can accept such values during initial development when you may not care about pickling, but once things are working, move the one-off function to a proper importable module and then it will be safe to use as a picklable value. One way to make this work smoothly is to create `param.ParameterizedFunction` objects or other \"function object\" classes (classes whose instances are callable like functions but which may have state and are fully picklable); see e.g. the `numbergen` module for examples.\n", "\n", - "2. **Skipping Parameters that should not be pickled**: In some cases, you may not _want_ the value of a given Parameter to be pickled and restored even while other state is being serialized. For instance, a Parameter whose value is set to a particular file path might cause errors if that path is restored when the pickle is loaded on a different system or once the file no longer exists. To cover such rare but potentially important cases, the Parameter can be defined with `pickle_default_value=False` (normally `True`), so that the instantaneous value is usable but won't be saved and restored with pickle.\n", + "2. **Skipping Parameters that should not be pickled [DEPRECATED in version 2.3.0]**: In some cases, you may not _want_ the value of a given Parameter to be pickled and restored even while other state is being serialized. For instance, a Parameter whose value is set to a particular file path might cause errors if that path is restored when the pickle is loaded on a different system or once the file no longer exists. To cover such rare but potentially important cases, the Parameter can be defined with `pickle_default_value=False` (normally `True`), so that the instantaneous value is usable but won't be saved and restored with pickle.\n", "\n", "3. **Customizing settting and getting state**: You may find that your Parameter or Parameterized objects have other state that you need to handle specially, whether that's to save and restore data that isn't otherwise picklable, or to ignore state that should _not_ be pickled. For instance, if your object's dictionary contains some object that doesn't support pickling, then you can add code to omit that or to serialize it in some special way that allows it to be restored, e.g. by extracting a state dictionary fom it and then restoring it from the dictionary later. See the [pickle docs](https://docs.python.org/3/library/pickle.html#pickle-state) for the `__getstate__` and `__setstate__` methods that you can implement on your Parameter or Parameterized objects to override this behavior. Be sure to call `super(YourClass,self).__setstate__(state)` or the getstate equivalent so that you also store parameters and dictionary values as usual, if desired.\n", "\n", diff --git a/param/parameterized.py b/param/parameterized.py index 3bbf6a267..a4ba52d44 100644 --- a/param/parameterized.py +++ b/param/parameterized.py @@ -36,6 +36,7 @@ from . import serializer from ._utils import ( DEFAULT_SIGNATURE, + ParamDeprecationWarning as _ParamDeprecationWarning, ParamFutureWarning as _ParamFutureWarning, Skip, _deprecated, @@ -1305,6 +1306,12 @@ class hierarchy (see ParameterizedMetaclass). self.readonly = readonly self._label = label self._set_instantiate(instantiate) + if pickle_default_value is False: + warnings.warn( + 'pickle_default_value has been deprecated.', + category=_ParamDeprecationWarning, + stacklevel=3, + ) self.pickle_default_value = pickle_default_value self._set_allow_None(allow_None) self.watchers = {} diff --git a/param/parameters.py b/param/parameters.py index 3d6447961..7d9730a60 100644 --- a/param/parameters.py +++ b/param/parameters.py @@ -2610,11 +2610,11 @@ class resolve_path(ParameterizedFunction): than just os.getcwd() can be used, and the file must exist. """ - search_paths = List(default=[os.getcwd()], pickle_default_value=False, doc=""" + search_paths = List(default=[os.getcwd()], pickle_default_value=None, doc=""" Prepended to a non-relative path, in order, until a file is found.""") - path_to_file = Boolean(default=True, pickle_default_value=False, + path_to_file = Boolean(default=True, pickle_default_value=None, allow_None=True, doc=""" String specifying whether the path refers to a 'File' or a 'Folder'. If None, the path may point to *either* a 'File' *or* @@ -2665,7 +2665,7 @@ class normalize_path(ParameterizedFunction): prefix rather than os.getcwd). """ - prefix = String(default=os.getcwd(),pickle_default_value=False,doc=""" + prefix = String(default=os.getcwd(),pickle_default_value=None,doc=""" Prepended to the specified path, if that path is not absolute.""") diff --git a/tests/testdeprecations.py b/tests/testdeprecations.py index a4e4162a0..99395eb7d 100644 --- a/tests/testdeprecations.py +++ b/tests/testdeprecations.py @@ -32,6 +32,11 @@ class P(param.Parameterized): with pytest.raises(param._utils.ParamFutureWarning): p.n = 1 + def test_deprecate_Parameter_pickle_default_value(self): + with pytest.raises(param._utils.ParamDeprecationWarning): + param.Parameter(pickle_default_value=False) + + class TestDeprecateInitModule: