Skip to content

Commit e9eed1e

Browse files
author
Laurent LAPORTE
committed
docs(tutorial): add documentation for deprecated parameters decorator
1 parent 969a6cd commit e9eed1e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

docs/source/_static/rusty-tools-background.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/source/tutorial.rst

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,50 @@ the :func:`~deprecated.deprecated` decorator patches the ``__new__`` method in o
123123
emmit the warning message before instance creation.
124124
125125
126+
Deprecated parameters
127+
---------------------
128+
129+
It is also possible to mark one or more parameters of a function as deprecated using the
130+
:func:`deprecated.params.deprecated_params` decorator.
131+
132+
Example:
133+
134+
.. code-block:: python
135+
136+
import warnings
137+
from deprecated.params import deprecated_params
138+
139+
class V2DeprecationWarning(DeprecationWarning):
140+
pass
141+
142+
# noinspection PyUnusedLocal
143+
@deprecated_params(
144+
{
145+
"epsilon": "epsilon is deprecated in version v2",
146+
"start": "start is removed in version v2",
147+
},
148+
category=V2DeprecationWarning,
149+
)
150+
@deprecated_params("epsilon", reason="epsilon is deprecated in version v1.1")
151+
def integrate(f, a, b, n=0, epsilon=0.0, start=None):
152+
epsilon = epsilon or (b - a) / n
153+
n = n or int((b - a) / epsilon)
154+
return sum((f(a + (i * epsilon)) + f(a + (i * epsilon) + epsilon)) * epsilon / 2 for i in range(n))
155+
156+
When the function is called, parameters marked as deprecated will emit deprecation
157+
warnings (using the provided category and message). This allows you to inform users
158+
about alternatives or the versions in which parameters were changed or removed.
159+
160+
.. code-block:: sh
161+
162+
$ python use_deprecated_params.py
163+
164+
use_deprecated_params.py:48: V2DeprecationWarning: epsilon is deprecated in version v2
165+
integrate(lambda x: x**2, 0, 2, epsilon=0.0012, start=123)
166+
use_deprecated_params.py:48: V2DeprecationWarning: start is removed in version v2
167+
integrate(lambda x: x**2, 0, 2, epsilon=0.0012, start=123)
168+
169+
126170
Controlling warnings
127171
--------------------
128172
@@ -193,7 +237,6 @@ When the user runs this script, the deprecation warnings for the 3.0 version are
193237
warning_classes_demo.py:30: DeprecatedIn26: Call to deprecated function (or staticmethod) foo. (deprecated function)
194238
foo()
195239
196-
197240
Filtering warnings locally
198241
--------------------------
199242
@@ -243,7 +286,6 @@ function will raise an exception because the *action* is set to "error".
243286
warnings.warn(msg, category=category, stacklevel=_stacklevel)
244287
DeprecationWarning: Call to deprecated function (or staticmethod) foo. (do not call it)
245288
246-
247289
Modifying the deprecated code reference
248290
---------------------------------------
249291

0 commit comments

Comments
 (0)