Skip to content

Commit 820cd8b

Browse files
committed
docs: fix docstrings showing usage in deprecated() function
1 parent c3bd3b8 commit 820cd8b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/diffpy/utils/_deprecator.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,31 @@ def deprecated(message, *, category=DeprecationWarning, stacklevel=1):
2020
2121
.. code-block:: python
2222
23-
from diffpy.utils._deprecator import deprecated, d
23+
from diffpy._deprecations import deprecated, deprecation_message
2424
25-
@deprecated("old_function is deprecated; use new_function instead")
25+
deprecation_warning = build_deprecation_message("diffpy.utils",
26+
"old_function",
27+
"new_function",
28+
"4.0.0")
29+
30+
@deprecated(deprecation_warning)
2631
def old_function(x, y):
27-
return x + y
32+
'''This function is deprecated and will be removed in version
33+
4.0.0. Please use new_function instead'''
34+
return new_function(x, y)
2835
2936
def new_function(x, y):
3037
return x + y
3138
32-
old_function(1, 2) # Emits DeprecationWarning
33-
new_function(1, 2) # No warning
39+
old_function(1, 2) # Works but emits DeprecationWarning
40+
new_function(1, 2) # Works, no warning
3441
3542
3643
Deprecating a class:
3744
3845
.. code-block:: python
3946
4047
from diffpy._deprecations import deprecated, deprecation_message
41-
import warnings
42-
43-
warnings.simplefilter("always", DeprecationWarning)
4448
4549
deprecation_warning = build_deprecation_message("diffpy.utils",
4650
"OldAtom",
@@ -49,8 +53,14 @@ def new_function(x, y):
4953
5054
@deprecated(deprecation_warning)
5155
class OldAtom:
52-
def __init__(self, symbol):
53-
self.symbol = symbol
56+
def __new__(cls, *args, **kwargs):
57+
warnings.warn(
58+
"OldAtom is deprecated and will be removed in
59+
version 4.0.0. Use NewClass instead.",
60+
DeprecationWarning,
61+
stacklevel=2,
62+
)
63+
return NewAtom(*args, **kwargs)
5464
5565
class NewAtom:
5666
def __init__(self, symbol):

0 commit comments

Comments
 (0)