Skip to content

Commit

Permalink
remove deprecated_function and deprecated_argument decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 committed Nov 15, 2024
1 parent 5de0232 commit 20c37a4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 100 deletions.
6 changes: 0 additions & 6 deletions qiskit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
.. autofunction:: add_deprecation_to_docstring
.. autofunction:: deprecate_arg
.. autofunction:: deprecate_arguments
.. autofunction:: deprecate_func
.. autofunction:: deprecate_function
SI unit conversion
==================
Expand Down Expand Up @@ -58,9 +56,7 @@
from .deprecation import (
add_deprecation_to_docstring,
deprecate_arg,
deprecate_arguments,
deprecate_func,
deprecate_function,
)
from .multiprocessing import local_hardware_info
from .multiprocessing import is_main_process
Expand All @@ -78,9 +74,7 @@
"LazySubprocessTester",
"add_deprecation_to_docstring",
"deprecate_arg",
"deprecate_arguments",
"deprecate_func",
"deprecate_function",
"local_hardware_info",
"is_main_process",
"apply_prefix",
Expand Down
94 changes: 0 additions & 94 deletions test/python/utils/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
from qiskit.utils.deprecation import (
add_deprecation_to_docstring,
deprecate_arg,
deprecate_arguments,
deprecate_func,
deprecate_function,
)
from test import QiskitTestCase # pylint: disable=wrong-import-order

Expand Down Expand Up @@ -164,51 +162,6 @@ def my_func() -> None:
),
)

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

@deprecate_arguments(
{"old_arg1": "new_arg1", "old_arg2": None},
category=PendingDeprecationWarning,
since="9.99",
)
def my_func() -> None:
pass

self.assertEqual(
my_func.__doc__,
dedent(
f"""\
.. deprecated:: 9.99_pending
{my_func.__qualname__} keyword argument old_arg1 is deprecated and replaced with \
new_arg1.
.. deprecated:: 9.99_pending
{my_func.__qualname__} keyword argument old_arg2 is deprecated and will in the \
future be removed.
"""
),
)

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

@deprecate_function("Stop using my_func!", since="9.99")
def my_func() -> None:
pass

self.assertEqual(
my_func.__doc__,
dedent(
"""\
.. deprecated:: 9.99
Stop using my_func!
"""
),
)

def test_deprecate_func_runtime_warning(self) -> None:
"""Test that `@deprecate_func` warns whenever the function is used."""

Expand Down Expand Up @@ -313,53 +266,6 @@ def my_func2(my_kwarg: int | None = None, **kwargs) -> None:
with self.assertWarnsRegex(DeprecationWarning, "my_kwarg"):
my_func2(my_kwarg=5, another_arg=0, yet_another=0)

def test_deprecate_arguments_runtime_warning(self) -> None:
"""Test that `@deprecate_arguments` warns whenever the arguments are used.
Also check that old arguments are passed in as their new alias.
"""

@deprecate_arguments({"arg1": "new_arg1", "arg2": None}, since="9.99")
def my_func(arg1: str = "a", arg2: str = "a", new_arg1: str | None = None) -> None:
del arg2
# If the old arg was set, we should set its `new_alias` to that value.
if arg1 != "a":
self.assertEqual(new_arg1, "z")
if new_arg1 is not None:
self.assertEqual(new_arg1, "z")

# No warnings if no deprecated args used.
my_func()
my_func(new_arg1="z")

# Warn if argument is specified, regardless of positional vs kwarg.
with self.assertWarnsRegex(DeprecationWarning, "arg1"):
my_func("z")
with self.assertWarnsRegex(DeprecationWarning, "arg1"):
my_func(arg1="z")
with self.assertWarnsRegex(DeprecationWarning, "arg2"):
my_func("z", "z")
with self.assertWarnsRegex(DeprecationWarning, "arg2"):
my_func(arg2="z")

# Error if new_alias specified at the same time as old argument name.
with self.assertRaises(TypeError):
my_func("a", new_arg1="z")
with self.assertRaises(TypeError):
my_func(arg1="a", new_arg1="z")
with self.assertRaises(TypeError):
my_func("a", "a", "z")

def test_deprecate_function_runtime_warning(self) -> None:
"""Test that `@deprecate_function` warns whenever the function is used."""

@deprecate_function("Stop using my_func!", since="9.99")
def my_func() -> None:
pass

with self.assertWarnsRegex(DeprecationWarning, "Stop using my_func!"):
my_func()


class AddDeprecationDocstringTest(QiskitTestCase):
"""Test that we correctly insert the deprecation directive at the right location.
Expand Down

0 comments on commit 20c37a4

Please sign in to comment.