Skip to content

Commit

Permalink
Addressing #11296 (comment)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Matthew Treinish <[email protected]>
  • Loading branch information
1ucian0 and mtreinish committed Nov 23, 2023
1 parent 6bf8f7f commit cd47576
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 11 additions & 5 deletions qiskit/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def deprecate_func(
additional_msg: str | None = None,
pending: bool = False,
package_name: str = "qiskit",
removal_timeline: str = "in the next major release",
removal_timeline: str | None = None,
is_property: bool = False,
):
"""Decorator to indicate a function has been deprecated.
Expand All @@ -46,7 +46,8 @@ def deprecate_func(
pending: Set to ``True`` if the deprecation is still pending.
package_name: The PyPI package name, e.g. "qiskit-nature".
removal_timeline: How soon can this deprecation be removed? Expects a value
like "in two major releases" or "in release 9.99".
like "in two major releases" or "in release 9.99". Default:
"in the next major release {since_major + 1}".
is_property: If the deprecated function is a `@property`, set this to True so that the
generated message correctly describes it as such. (This isn't necessary for
property setters, as their docstring is ignored by Python.)
Expand Down Expand Up @@ -111,7 +112,7 @@ def deprecate_arg(
package_name: str = "qiskit",
new_alias: str | None = None,
predicate: Callable[[Any], bool] | None = None,
removal_timeline: str = "in the next major release",
removal_timeline: str | None = None,
):
"""Decorator to indicate an argument has been deprecated in some way.
Expand All @@ -138,7 +139,8 @@ def deprecate_arg(
`lambda my_arg: isinstance(my_arg, dict)`. Regardless of if a predicate is set, the
runtime warning will only log when the user specifies the argument.
removal_timeline: How soon can this deprecation be removed? Expects a value
like "in two major releases" or "in release 9.99".
like "in two major releases" or "in release 9.99". Default:
"in the next major release {since_major + 1}".
Returns:
Callable: The decorated callable.
Expand Down Expand Up @@ -353,8 +355,12 @@ def _write_deprecation_msg(
since: str,
pending: bool,
additional_msg: str,
removal_timeline: str,
removal_timeline: str | None,
) -> tuple[str, Type[DeprecationWarning] | Type[PendingDeprecationWarning]]:
if not removal_timeline:
removal_major = int(since.split(".")[0]) + 1
removal_timeline = f"in the next major release {removal_major}.0"

if pending:
category: Type[DeprecationWarning] | Type[
PendingDeprecationWarning
Expand Down
13 changes: 6 additions & 7 deletions test/python/utils/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_deprecate_func_docstring(self) -> None:
.. deprecated:: 9.99_pending
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.
will be marked deprecated in a future release, and then removed in the next major release 10.0.
"""
),
)
Expand All @@ -97,7 +96,7 @@ def test_deprecate_func_docstring(self) -> None:
.. deprecated:: 9.99
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!
9.99. It will be removed in the next major release 10.0. Stop using this!
"""
),
)
Expand All @@ -109,7 +108,7 @@ def test_deprecate_func_docstring(self) -> None:
.. deprecated:: 9.99
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.
9.99. It will be removed in the next major release 10.0.
"""
),
)
Expand Down Expand Up @@ -143,18 +142,18 @@ 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 in the next major release 10.0. Instead, \
use foo.
.. deprecated:: 9.99
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``, \
removed in the next major release 10.0. 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 \
removed no earlier than 3 months after the release date.
removed in the next major release 10.0.
.. deprecated:: 9.99
``{__name__}.{my_func.__qualname__}()``'s argument ``arg1`` is deprecated as of \
Expand Down

0 comments on commit cd47576

Please sign in to comment.