Skip to content

Commit

Permalink
Fix tests, update docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Nov 19, 2024
1 parent b063410 commit 5dd8262
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions qiskit/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def deprecate_func(
For example, "Instead, use the function ``new_func`` from the module
``<my_module>.<my_submodule>``, which is similar but uses GPU acceleration."
pending: Set to ``True`` if the deprecation is still pending.
package_name: The PyPI package name, e.g. "qiskit-nature".
package_name: The package name shown in the deprecation message (e.g. the PyPI package name).
removal_timeline: How soon can this deprecation be removed? Expects a value
like "no sooner than 6 months after the latest release" or "in release 9.99".
is_property: If the deprecated function is a `@property`, set this to True so that the
Expand Down Expand Up @@ -130,7 +130,7 @@ def deprecate_arg(
(if new_alias is not set). For example, "Instead, use the argument `new_arg`,
which is similar but does not impact the circuit's setup."
pending: Set to `True` if the deprecation is still pending.
package_name: The PyPI package name, e.g. "qiskit-nature".
package_name: The package name shown in the deprecation message (e.g. the PyPI package name).
new_alias: If the arg has simply been renamed, set this to the new name. The decorator will
dynamically update the `kwargs` so that when the user sets the old arg, it will be
passed in as the `new_alias` arg.
Expand Down
26 changes: 18 additions & 8 deletions test/python/utils/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_deprecate_func_docstring(self) -> None:
f"""\
.. deprecated:: 9.99
The function ``{__name__}._deprecated_func()`` is deprecated as of qiskit \
The function ``{__name__}._deprecated_func()`` is deprecated as of Qiskit \
9.99. It will be removed in 2 releases. Instead, use new_func().
"""
),
Expand All @@ -84,7 +84,7 @@ def test_deprecate_func_docstring(self) -> None:
f"""\
.. deprecated:: 9.99_pending
The class ``{__name__}._Foo`` is pending deprecation as of qiskit 9.99. It \
The class ``{__name__}._Foo`` is pending deprecation as of Qiskit 9.99. It \
will be marked deprecated in a future release, and then removed no earlier than 3 months after \
the release date.
"""
Expand All @@ -97,7 +97,7 @@ def test_deprecate_func_docstring(self) -> None:
Method.
.. deprecated:: 9.99
The method ``{__name__}._Foo.my_method()`` is deprecated as of qiskit \
The method ``{__name__}._Foo.my_method()`` is deprecated as of Qiskit \
9.99. It will be removed no earlier than 3 months after the release date. Stop using this!
"""
),
Expand All @@ -109,12 +109,22 @@ def test_deprecate_func_docstring(self) -> None:
Property.
.. deprecated:: 9.99
The property ``{__name__}._Foo.my_property`` is deprecated as of qiskit \
The property ``{__name__}._Foo.my_property`` is deprecated as of Qiskit \
9.99. It will be removed no earlier than 3 months after the release date.
"""
),
)

def test_deprecate_func_package_name(self) -> None:
"""Test setting the package name works."""

@deprecate_func(since="9.99", package_name="riskit")
def my_func() -> None:
pass

with self.assertWarnsRegex(DeprecationWarning, "is deprecated as of riskit 9.99"):
my_func()

def test_deprecate_arg_docstring(self) -> None:
"""Test that `@deprecate_arg` adds the correct message to the docstring."""

Expand Down Expand Up @@ -144,22 +154,22 @@ def my_func() -> None:
.. deprecated:: 9.99
``{__name__}.{my_func.__qualname__}()``'s argument ``arg4`` is deprecated as of \
qiskit 9.99. It will be removed no earlier than 3 months after the release date. Instead, \
Qiskit 9.99. It will be removed no earlier than 3 months after the release date. Instead, \
use foo.
.. deprecated:: 9.99
Using the argument arg3 is deprecated as of qiskit 9.99. It will be \
Using the argument arg3 is deprecated as of Qiskit 9.99. It will be \
removed no earlier than 3 months after the release date. Instead, use the argument ``new_arg3``, \
which behaves identically.
.. deprecated:: 9.99_pending
``{__name__}.{my_func.__qualname__}()``'s argument ``arg2`` is pending \
deprecation as of qiskit 9.99. It will be marked deprecated in a future release, and then \
deprecation as of Qiskit 9.99. It will be marked deprecated in a future release, and then \
removed no earlier than 3 months after the release date.
.. deprecated:: 9.99
``{__name__}.{my_func.__qualname__}()``'s argument ``arg1`` is deprecated as of \
qiskit 9.99. It will be removed in 2 releases.
Qiskit 9.99. It will be removed in 2 releases.
"""
),
)
Expand Down

0 comments on commit 5dd8262

Please sign in to comment.