From 20c37a4fb6342a65f4044b37dcdaffd8dc8536cc Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Fri, 15 Nov 2024 20:36:51 +0100 Subject: [PATCH] remove deprecated_function and deprecated_argument decorators --- qiskit/utils/__init__.py | 6 -- test/python/utils/test_deprecation.py | 94 --------------------------- 2 files changed, 100 deletions(-) diff --git a/qiskit/utils/__init__.py b/qiskit/utils/__init__.py index 30935437ebf2..c6b73e09ff28 100644 --- a/qiskit/utils/__init__.py +++ b/qiskit/utils/__init__.py @@ -23,9 +23,7 @@ .. autofunction:: add_deprecation_to_docstring .. autofunction:: deprecate_arg -.. autofunction:: deprecate_arguments .. autofunction:: deprecate_func -.. autofunction:: deprecate_function SI unit conversion ================== @@ -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 @@ -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", diff --git a/test/python/utils/test_deprecation.py b/test/python/utils/test_deprecation.py index 08872b9e7a41..1e2f98b17263 100644 --- a/test/python/utils/test_deprecation.py +++ b/test/python/utils/test_deprecation.py @@ -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 @@ -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.""" @@ -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.