diff --git a/qiskit/algorithms/amplitude_amplifiers/grover.py b/qiskit/algorithms/amplitude_amplifiers/grover.py index 1ca778ae1c5..0e0c1decd0e 100644 --- a/qiskit/algorithms/amplitude_amplifiers/grover.py +++ b/qiskit/algorithms/amplitude_amplifiers/grover.py @@ -196,6 +196,7 @@ def __init__( "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self) -> Optional[QuantumInstance]: r"""Pending deprecation\; Get the quantum instance. @@ -211,6 +212,7 @@ def quantum_instance(self) -> Optional[QuantumInstance]: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self, quantum_instance: Union[QuantumInstance, Backend]) -> None: r"""Pending deprecation\; Set quantum instance. diff --git a/qiskit/algorithms/amplitude_estimators/ae.py b/qiskit/algorithms/amplitude_estimators/ae.py index f79419706cd..91521eede70 100644 --- a/qiskit/algorithms/amplitude_estimators/ae.py +++ b/qiskit/algorithms/amplitude_estimators/ae.py @@ -129,6 +129,7 @@ def sampler(self, sampler: BaseSampler) -> None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self) -> QuantumInstance | None: """Pending deprecation; Get the quantum instance. @@ -144,6 +145,7 @@ def quantum_instance(self) -> QuantumInstance | None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: """Pending deprecation; Set quantum instance. diff --git a/qiskit/algorithms/amplitude_estimators/fae.py b/qiskit/algorithms/amplitude_estimators/fae.py index 14de1655481..c1bb0eec984 100644 --- a/qiskit/algorithms/amplitude_estimators/fae.py +++ b/qiskit/algorithms/amplitude_estimators/fae.py @@ -114,6 +114,7 @@ def sampler(self, sampler: BaseSampler) -> None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self) -> QuantumInstance | None: """Pending deprecation; Get the quantum instance. @@ -129,6 +130,7 @@ def quantum_instance(self) -> QuantumInstance | None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: """Pending deprecation; Set quantum instance. diff --git a/qiskit/algorithms/amplitude_estimators/iae.py b/qiskit/algorithms/amplitude_estimators/iae.py index a1f6bb14a1a..0b0348c15ad 100644 --- a/qiskit/algorithms/amplitude_estimators/iae.py +++ b/qiskit/algorithms/amplitude_estimators/iae.py @@ -137,6 +137,7 @@ def sampler(self, sampler: BaseSampler) -> None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self) -> QuantumInstance | None: """Pending deprecation; Get the quantum instance. @@ -152,6 +153,7 @@ def quantum_instance(self) -> QuantumInstance | None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: """Pending deprecation; Set quantum instance. diff --git a/qiskit/algorithms/amplitude_estimators/mlae.py b/qiskit/algorithms/amplitude_estimators/mlae.py index 2113a405995..45ab626ce50 100644 --- a/qiskit/algorithms/amplitude_estimators/mlae.py +++ b/qiskit/algorithms/amplitude_estimators/mlae.py @@ -141,6 +141,7 @@ def sampler(self, sampler: BaseSampler) -> None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self) -> QuantumInstance | None: """Pending deprecation; Get the quantum instance. @@ -156,6 +157,7 @@ def quantum_instance(self) -> QuantumInstance | None: "This property will be deprecated in a future release and subsequently " "removed after that.", category=PendingDeprecationWarning, + since="0.23.0", ) def quantum_instance(self, quantum_instance: QuantumInstance | Backend) -> None: """Pending deprecation; Set quantum instance. diff --git a/qiskit/algorithms/aux_ops_evaluator.py b/qiskit/algorithms/aux_ops_evaluator.py index 9ce9349a7de..87c9cb9427a 100644 --- a/qiskit/algorithms/aux_ops_evaluator.py +++ b/qiskit/algorithms/aux_ops_evaluator.py @@ -33,10 +33,9 @@ @deprecate_function( "The eval_observables function has been superseded by the " - "qiskit.algorithms.observables_evaluator.estimate_observables function. " - "This function will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.observables_evaluator.estimate_observables function. ", category=PendingDeprecationWarning, + since="0.23.0", ) def eval_observables( quantum_instance: Union[QuantumInstance, Backend], diff --git a/qiskit/algorithms/eigen_solvers/eigen_solver.py b/qiskit/algorithms/eigen_solvers/eigen_solver.py index a013b5c827c..1eab2e8b625 100644 --- a/qiskit/algorithms/eigen_solvers/eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/eigen_solver.py @@ -38,10 +38,9 @@ class Eigensolver(ABC): @deprecate_function( "The Eigensolver interface has been superseded by the " - "qiskit.algorithms.eigensolvers.Eigensolver interface. " - "This interface will be deprecated in a future release and subsequently " - "removed after that.", - category=PendingDeprecationWarning, + "qiskit.algorithms.eigensolvers.Eigensolver interface. ", + category=DeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: pass @@ -90,10 +89,9 @@ class EigensolverResult(AlgorithmResult): @deprecate_function( "The EigensolverResult class has been superseded by the " - "qiskit.algorithms.eigensolvers.EigensolverResult class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.eigensolvers.EigensolverResult class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py old mode 100755 new mode 100644 index 77078dd6fbb..4125a4b7d85 --- a/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py +++ b/qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py @@ -51,10 +51,9 @@ class NumPyEigensolver(Eigensolver): @deprecate_function( "The NumPyEigensolver class has been superseded by the " - "qiskit.algorithms.eigensolvers.NumPyEigensolver class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.eigensolvers.NumPyEigensolver class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/eigen_solvers/vqd.py b/qiskit/algorithms/eigen_solvers/vqd.py index d14ac038e1f..f7ae5142e84 100644 --- a/qiskit/algorithms/eigen_solvers/vqd.py +++ b/qiskit/algorithms/eigen_solvers/vqd.py @@ -97,11 +97,9 @@ class VQD(VariationalAlgorithm, Eigensolver): """ @deprecate_function( - "The VQD class has been superseded by the " - "qiskit.algorithms.eigensolvers.VQD class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "The VQD class has been superseded by the " "qiskit.algorithms.eigensolvers.VQD class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, @@ -768,10 +766,9 @@ class VQDResult(VariationalResult, EigensolverResult): @deprecate_function( "The VQDResult class has been superseded by the " - "qiskit.algorithms.eigensolvers.VQDResult class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.eigensolvers.VQDResult class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/evolvers/evolution_problem.py b/qiskit/algorithms/evolvers/evolution_problem.py index cd34c5a34f8..4344c60c815 100644 --- a/qiskit/algorithms/evolvers/evolution_problem.py +++ b/qiskit/algorithms/evolvers/evolution_problem.py @@ -35,10 +35,9 @@ class EvolutionProblem: @deprecate_function( "The EvolutionProblem class has been superseded by the " - "qiskit.algorithms.time_evolvers.TimeEvolutionProblem class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.time_evolvers.TimeEvolutionProblem class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/evolvers/evolution_result.py b/qiskit/algorithms/evolvers/evolution_result.py index 9ae567ca91c..57507660d1e 100644 --- a/qiskit/algorithms/evolvers/evolution_result.py +++ b/qiskit/algorithms/evolvers/evolution_result.py @@ -33,10 +33,9 @@ class EvolutionResult(AlgorithmResult): @deprecate_function( "The EvolutionResult class has been superseded by the " - "qiskit.algorithms.time_evolvers.TimeEvolutionResult class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.time_evolvers.TimeEvolutionResult class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/evolvers/imaginary_evolver.py b/qiskit/algorithms/evolvers/imaginary_evolver.py index 37a24d266a3..90514379094 100644 --- a/qiskit/algorithms/evolvers/imaginary_evolver.py +++ b/qiskit/algorithms/evolvers/imaginary_evolver.py @@ -31,10 +31,9 @@ class ImaginaryEvolver(ABC): @deprecate_function( "The ImaginaryEvolver interface has been superseded by the " - "qiskit.algorithms.time_evolvers.ImaginaryTimeEvolver interface. " - "This interface will be deprecated in a future release and subsequently " - "removed after that.", - category=PendingDeprecationWarning, + "qiskit.algorithms.time_evolvers.ImaginaryTimeEvolver interface. ", + category=DeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/evolvers/real_evolver.py b/qiskit/algorithms/evolvers/real_evolver.py index c869344a19b..0489e4378d6 100644 --- a/qiskit/algorithms/evolvers/real_evolver.py +++ b/qiskit/algorithms/evolvers/real_evolver.py @@ -31,10 +31,9 @@ class RealEvolver(ABC): @deprecate_function( "The RealEvolver interface has been superseded by the " - "qiskit.algorithms.time_evolvers.RealTimeEvolver interface. " - "This interface will be deprecated in a future release and subsequently " - "removed after that.", - category=PendingDeprecationWarning, + "qiskit.algorithms.time_evolvers.RealTimeEvolver interface. ", + category=DeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py index 323305b4b8c..273c5e86eba 100644 --- a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py +++ b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py @@ -66,10 +66,9 @@ class TrotterQRTE(RealEvolver): @deprecate_function( "The TrotterQRTE class has been superseded by the " - "qiskit.algorithms.time_evolvers.trotterization.TrotterQRTE class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.time_evolvers.trotterization.TrotterQRTE class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/factorizers/shor.py b/qiskit/algorithms/factorizers/shor.py index 7f700e76889..3b79f5554aa 100644 --- a/qiskit/algorithms/factorizers/shor.py +++ b/qiskit/algorithms/factorizers/shor.py @@ -60,7 +60,8 @@ class Shor: """The Shor class is deprecated as of Qiskit Terra 0.22.0 and will be removed no sooner than 3 months after the release date. It is replaced by the tutorial at https://qiskit.org/textbook/ch-algorithms/shor.html - """ + """, + since="0.22.0", ) def __init__(self, quantum_instance: Optional[Union[QuantumInstance, Backend]] = None) -> None: """ diff --git a/qiskit/algorithms/linear_solvers/hhl.py b/qiskit/algorithms/linear_solvers/hhl.py index 92ddda7f845..9b3a4f622f8 100644 --- a/qiskit/algorithms/linear_solvers/hhl.py +++ b/qiskit/algorithms/linear_solvers/hhl.py @@ -110,7 +110,8 @@ class HHL(LinearSolver): """The HHL class is deprecated as of Qiskit Terra 0.22.0 and will be removed no sooner than 3 months after the release date. It is replaced by the tutorial at https://qiskit.org/textbook/ch-applications/hhl_tutorial.html" - """ + """, + since="0.22.0", ) def __init__( self, diff --git a/qiskit/algorithms/linear_solvers/linear_solver.py b/qiskit/algorithms/linear_solvers/linear_solver.py index 97a68226ebb..11d604c859c 100644 --- a/qiskit/algorithms/linear_solvers/linear_solver.py +++ b/qiskit/algorithms/linear_solvers/linear_solver.py @@ -34,7 +34,8 @@ class LinearSolverResult(AlgorithmResult): @deprecate_function( "The LinearSolverResult class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self) -> None: super().__init__() @@ -102,7 +103,8 @@ class LinearSolver(ABC): @deprecate_function( "The LinearSolver class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/linear_solvers/matrices/linear_system_matrix.py b/qiskit/algorithms/linear_solvers/matrices/linear_system_matrix.py index 26e53860dc1..69263e96345 100644 --- a/qiskit/algorithms/linear_solvers/matrices/linear_system_matrix.py +++ b/qiskit/algorithms/linear_solvers/matrices/linear_system_matrix.py @@ -25,7 +25,8 @@ class LinearSystemMatrix(BlueprintCircuit, ABC): @deprecate_function( "The LinearSystemMatrix class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__( self, diff --git a/qiskit/algorithms/linear_solvers/matrices/numpy_matrix.py b/qiskit/algorithms/linear_solvers/matrices/numpy_matrix.py index 2ffdc54c09e..d404e33fbf1 100644 --- a/qiskit/algorithms/linear_solvers/matrices/numpy_matrix.py +++ b/qiskit/algorithms/linear_solvers/matrices/numpy_matrix.py @@ -48,7 +48,8 @@ class NumPyMatrix(LinearSystemMatrix): @deprecate_function( "The NumPyMatrix class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__( self, diff --git a/qiskit/algorithms/linear_solvers/matrices/tridiagonal_toeplitz.py b/qiskit/algorithms/linear_solvers/matrices/tridiagonal_toeplitz.py index 325554c8fb6..ff431af793b 100644 --- a/qiskit/algorithms/linear_solvers/matrices/tridiagonal_toeplitz.py +++ b/qiskit/algorithms/linear_solvers/matrices/tridiagonal_toeplitz.py @@ -60,7 +60,8 @@ class TridiagonalToeplitz(LinearSystemMatrix): @deprecate_function( "The TridiagonalToeplitz class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__( self, diff --git a/qiskit/algorithms/linear_solvers/numpy_linear_solver.py b/qiskit/algorithms/linear_solvers/numpy_linear_solver.py index d85c0920baf..b0f6f80c200 100644 --- a/qiskit/algorithms/linear_solvers/numpy_linear_solver.py +++ b/qiskit/algorithms/linear_solvers/numpy_linear_solver.py @@ -53,7 +53,8 @@ class NumPyLinearSolver(LinearSolver): @deprecate_function( "The NumPyLinearSolver class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/linear_solvers/observables/absolute_average.py b/qiskit/algorithms/linear_solvers/observables/absolute_average.py index ae0b930d944..3cfe25d9ba3 100644 --- a/qiskit/algorithms/linear_solvers/observables/absolute_average.py +++ b/qiskit/algorithms/linear_solvers/observables/absolute_average.py @@ -63,7 +63,8 @@ class AbsoluteAverage(LinearSystemObservable): @deprecate_function( "The AbsoluteAverage class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/linear_solvers/observables/linear_system_observable.py b/qiskit/algorithms/linear_solvers/observables/linear_system_observable.py index fd6ea233973..7beb7c18cb2 100644 --- a/qiskit/algorithms/linear_solvers/observables/linear_system_observable.py +++ b/qiskit/algorithms/linear_solvers/observables/linear_system_observable.py @@ -26,7 +26,8 @@ class LinearSystemObservable(ABC): @deprecate_function( "The LinearSystemObservable class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self) -> None: pass diff --git a/qiskit/algorithms/linear_solvers/observables/matrix_functional.py b/qiskit/algorithms/linear_solvers/observables/matrix_functional.py index 0b584ba3b4a..03672a8d7d9 100644 --- a/qiskit/algorithms/linear_solvers/observables/matrix_functional.py +++ b/qiskit/algorithms/linear_solvers/observables/matrix_functional.py @@ -75,7 +75,8 @@ class MatrixFunctional(LinearSystemObservable): @deprecate_function( "The MatrixFunctional class is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " + "and will be removed no sooner than 3 months after the release date. ", + since="0.22.0", ) def __init__(self, main_diag: float, off_diag: int) -> None: """ diff --git a/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py b/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py index 373876a9e04..bf7a4b8448b 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py +++ b/qiskit/algorithms/minimum_eigen_solvers/minimum_eigen_solver.py @@ -38,10 +38,9 @@ class MinimumEigensolver(ABC): @deprecate_function( "The Minimum Eigensolver interface has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver interface. " - "This interface will be deprecated in a future release and subsequently " - "removed after that.", - category=PendingDeprecationWarning, + "qiskit.algorithms.minimum_eigensolvers.MinimumEigensolver interface. ", + category=DeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: pass @@ -94,10 +93,9 @@ class MinimumEigensolverResult(AlgorithmResult): @deprecate_function( "The MinimumEigensolverResult class has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult class.", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: super().__init__() diff --git a/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py b/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py index 191a130a016..9bcb37e2105 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py +++ b/qiskit/algorithms/minimum_eigen_solvers/numpy_minimum_eigen_solver.py @@ -39,10 +39,9 @@ class NumPyMinimumEigensolver(MinimumEigensolver): @deprecate_function( "The NumPyMinimumEigensolver class has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/minimum_eigen_solvers/qaoa.py b/qiskit/algorithms/minimum_eigen_solvers/qaoa.py index e650ee349cb..914522efa3a 100644 --- a/qiskit/algorithms/minimum_eigen_solvers/qaoa.py +++ b/qiskit/algorithms/minimum_eigen_solvers/qaoa.py @@ -61,10 +61,9 @@ class QAOA(VQE): @deprecate_function( "The QAOA class has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.QAOA class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.minimum_eigensolvers.QAOA class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, diff --git a/qiskit/algorithms/minimum_eigen_solvers/vqe.py b/qiskit/algorithms/minimum_eigen_solvers/vqe.py old mode 100755 new mode 100644 index 28629862042..c9a4aeff1db --- a/qiskit/algorithms/minimum_eigen_solvers/vqe.py +++ b/qiskit/algorithms/minimum_eigen_solvers/vqe.py @@ -129,10 +129,9 @@ def my_minimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult: @deprecate_function( "The VQE class has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.VQE class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.minimum_eigensolvers.VQE class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__( self, @@ -668,10 +667,9 @@ class VQEResult(VariationalResult, MinimumEigensolverResult): @deprecate_function( "The VQEResult class has been superseded by the " - "qiskit.algorithms.minimum_eigensolvers.VQEResult class. " - "This class will be deprecated in a future release and subsequently " - "removed after that.", + "qiskit.algorithms.minimum_eigensolvers.VQEResult class. ", category=PendingDeprecationWarning, + since="0.23.0", ) def __init__(self) -> None: with warnings.catch_warnings(): diff --git a/qiskit/algorithms/optimizers/adam_amsgrad.py b/qiskit/algorithms/optimizers/adam_amsgrad.py index ee305e00f44..c1c9a64bdbc 100644 --- a/qiskit/algorithms/optimizers/adam_amsgrad.py +++ b/qiskit/algorithms/optimizers/adam_amsgrad.py @@ -198,7 +198,8 @@ def load_params(self, load_dir: str) -> None: "objective_function": "fun", "initial_point": "x0", "gradient_function": "jac", - } + }, + since="0.19.0", ) # pylint: disable=arguments-differ def minimize( diff --git a/qiskit/algorithms/optimizers/spsa.py b/qiskit/algorithms/optimizers/spsa.py index ac70f8a0a6f..7888821508f 100644 --- a/qiskit/algorithms/optimizers/spsa.py +++ b/qiskit/algorithms/optimizers/spsa.py @@ -651,7 +651,8 @@ def get_support_level(self): "The SPSA.optimize method is deprecated as of Qiskit Terra 0.21.0 and will be removed no " "sooner than 3 months after the release date. Instead, use SPSA.minimize as a replacement, " "which supports the same arguments but follows the interface of scipy.optimize and returns " - "a complete result object containing additional information." + "a complete result object containing additional information.", + since="0.21.0", ) def optimize( self, diff --git a/qiskit/algorithms/phase_estimators/phase_estimation_result.py b/qiskit/algorithms/phase_estimators/phase_estimation_result.py index 0a9b8299758..354338df6f3 100644 --- a/qiskit/algorithms/phase_estimators/phase_estimation_result.py +++ b/qiskit/algorithms/phase_estimators/phase_estimation_result.py @@ -70,7 +70,8 @@ def circuit_result(self) -> Result: @deprecate_function( """The 'PhaseEstimationResult.most_likely_phase' attribute is deprecated as of 0.18.0 and will be removed no earlier than 3 months - after the release date. It has been renamed as the 'phase' attribute.""" + after the release date. It has been renamed as the 'phase' attribute.""", + since="0.18.0", ) def most_likely_phase(self) -> float: r"""DEPRECATED - Return the most likely phase as a number in :math:`[0.0, 1.0)`. diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index 60aa846b3da..22bec1e296f 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -509,7 +509,8 @@ def _add_op_node(self, op, qargs, cargs): """The DAGCircuit._copy_circuit_metadata method is deprecated as of 0.20.0. It will be removed no earlier than 3 months after the release date. You should use the DAGCircuit.copy_empty_like method instead, which acts identically. - """ + """, + since="0.20.0", ) def _copy_circuit_metadata(self): """DEPRECATED""" diff --git a/qiskit/primitives/base/base_estimator.py b/qiskit/primitives/base/base_estimator.py index 4a525ad0c75..309a089c5ec 100644 --- a/qiskit/primitives/base/base_estimator.py +++ b/qiskit/primitives/base/base_estimator.py @@ -340,17 +340,17 @@ def parameters(self) -> tuple[ParameterView, ...]: return tuple(self._parameters) @deprecate_function( - "The BaseEstimator.__enter__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " + "The BaseEstimator.__enter__ method is deprecated. " "BaseEstimator should be initialized directly.", + since="0.22.0", ) def __enter__(self): return self @deprecate_function( - "The BaseEstimator.__call__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " + "The BaseEstimator.__call__ method is deprecated. " "BaseEstimator should be initialized directly.", + since="0.22.0", ) def __exit__(self, *exc_info): self.close() @@ -360,11 +360,12 @@ def close(self): ... @deprecate_function( - "The BaseEstimator.__call__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " - "Use the 'run' method instead.", + "The BaseEstimator.__call__ method is deprecated. " "Use the 'run' method instead.", + since="0.22.0", + ) + @deprecate_arguments( + {"circuit_indices": "circuits", "observable_indices": "observables"}, since="0.21.0" ) - @deprecate_arguments({"circuit_indices": "circuits", "observable_indices": "observables"}) def __call__( self, circuits: Sequence[int | QuantumCircuit], diff --git a/qiskit/primitives/base/base_sampler.py b/qiskit/primitives/base/base_sampler.py index 5c68ea29ba8..69dc933367c 100644 --- a/qiskit/primitives/base/base_sampler.py +++ b/qiskit/primitives/base/base_sampler.py @@ -257,17 +257,17 @@ def parameters(self) -> tuple[ParameterView, ...]: return tuple(self._parameters) @deprecate_function( - "The BaseSampler.__enter__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " + "The BaseSampler.__enter__ method is deprecated. " "BaseSampler should be initialized directly.", + since="0.22.0", ) def __enter__(self): return self @deprecate_function( - "The BaseSampler.__exit__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " + "The BaseSampler.__exit__ method is deprecated. " "BaseSampler should be initialized directly.", + since="0.22.0", ) def __exit__(self, *exc_info): self.close() @@ -277,11 +277,9 @@ def close(self): ... @deprecate_function( - "The BaseSampler.__call__ method is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the releasedate. " - "Use run method instead.", + "The BaseSampler.__call__ method is deprecated. " "Use run method instead.", since="0.22.0" ) - @deprecate_arguments({"circuit_indices": "circuits"}) + @deprecate_arguments({"circuit_indices": "circuits"}, since="0.21.0") def __call__( self, circuits: Sequence[int | QuantumCircuit], diff --git a/qiskit/pulse/utils.py b/qiskit/pulse/utils.py index c5f77749e4e..9756dc5cece 100644 --- a/qiskit/pulse/utils.py +++ b/qiskit/pulse/utils.py @@ -98,7 +98,7 @@ def instruction_duration_validation(duration: int): ) -@deprecate_function("Deprecated since Terra 0.22.0. Use 'qiskit.utils.deprecate_function' instead.") +@deprecate_function("Use 'qiskit.utils.deprecate_function' instead.", since="0.22.0") def deprecated_functionality(func): """A decorator that raises deprecation warning without showing alternative method.""" return deprecate_function( @@ -106,6 +106,7 @@ def deprecated_functionality(func): "No alternative method will be provided with this change. " "If there is any practical usage of this functionality, please write " "an issue in Qiskit/qiskit-terra repository.", - category=DeprecationWarning, stacklevel=2, + category=DeprecationWarning, + modify_docstring=False, )(func) diff --git a/qiskit/qpy/interface.py b/qiskit/qpy/interface.py index 075a6435050..4c7dd066bba 100644 --- a/qiskit/qpy/interface.py +++ b/qiskit/qpy/interface.py @@ -72,7 +72,7 @@ VERSION_PATTERN_REGEX = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE) -@deprecate_arguments({"circuits": "programs"}) +@deprecate_arguments({"circuits": "programs"}, since="0.21.0") def dump( programs: Union[List[QPY_SUPPORTED_TYPES], QPY_SUPPORTED_TYPES], file_obj: BinaryIO, diff --git a/qiskit/quantum_info/operators/symplectic/random.py b/qiskit/quantum_info/operators/symplectic/random.py index 4cea74684e2..2fa8f7ebeb6 100644 --- a/qiskit/quantum_info/operators/symplectic/random.py +++ b/qiskit/quantum_info/operators/symplectic/random.py @@ -104,9 +104,10 @@ def random_pauli_table(num_qubits, size=1, seed=None): @deprecate_function( - "The random_stabilizer_table function is deprecated as of Qiskit Terra 0.22.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use random_pauli_list method instead." # pylint: disable=bad-docstring-quotes + """The random_stabilizer_table function is deprecated as of Qiskit Terra 0.22.0 + and will be removed no sooner than 3 months after the release date. + Use random_pauli_list method instead.""", + since="0.22.0", ) def random_stabilizer_table(num_qubits, size=1, seed=None): """DEPRECATED: Return a random StabilizerTable. diff --git a/qiskit/scheduler/utils.py b/qiskit/scheduler/utils.py index 5df6918dcb0..ee1cc014ae4 100644 --- a/qiskit/scheduler/utils.py +++ b/qiskit/scheduler/utils.py @@ -15,12 +15,14 @@ from qiskit.utils.deprecation import deprecate_function from qiskit.pulse import macros, utils -format_meas_map = deprecate_function('"format_meas_map" has been moved to "qiskit.pulse.utils"')( - utils.format_meas_map -) - -measure = deprecate_function('"measure" has been moved to "qiskit.pulse.macros"')(macros.measure) +format_meas_map = deprecate_function( + '"format_meas_map" has been moved to "qiskit.pulse.utils"', since="0.15.0" +)(utils.format_meas_map) -measure_all = deprecate_function('"measure_all" has been moved to "qiskit.pulse.macros"')( - macros.measure_all +measure = deprecate_function('"measure" has been moved to "qiskit.pulse.macros"', since="0.15.0")( + macros.measure ) + +measure_all = deprecate_function( + '"measure_all" has been moved to "qiskit.pulse.macros"', since="0.15.0" +)(macros.measure_all) diff --git a/qiskit/utils/deprecation.py b/qiskit/utils/deprecation.py index 633c2472288..e1c7a583911 100644 --- a/qiskit/utils/deprecation.py +++ b/qiskit/utils/deprecation.py @@ -12,15 +12,34 @@ """Deprecation utilities""" +import re import functools import warnings from typing import Type +identifier = re.compile("[a-zA-Z_][a-zA-Z0-9_]*") -def deprecate_arguments(kwarg_map, category: Type[Warning] = DeprecationWarning): - """Decorator to automatically alias deprecated argument names and warn upon use.""" + +def deprecate_arguments( + kwarg_map, category: Type[Warning] = DeprecationWarning, modify_docstring=True, since=None +): + """Decorator to automatically alias deprecated argument names and warn upon use.""" def decorator(func): + # TODO Remove the qobj guard once https://github.com/Qiskit/qiskit-aer/pull/1635 is released + if modify_docstring and since is None and "qobj" not in kwarg_map: + # TODO: replace with: raise QiskitError( + warnings.warn( + "Adding a 'deprecated' directive to the docstring needs a version. Add parameter `since`" + " to `deprecate_arguments` or disable docstring annotation with `modify_docstring=False`" + ". This warning will be a QiskitError exception in qiskit-terra 0.23.", + stacklevel=4, + category=FutureWarning, + ) + + if modify_docstring and kwarg_map: + func.__doc__ = "\n".join(_extend_docstring(func, since or "unknown_version", kwarg_map)) + @functools.wraps(func) def wrapper(*args, **kwargs): if kwargs: @@ -32,19 +51,45 @@ def wrapper(*args, **kwargs): return decorator -def deprecate_function(msg: str, stacklevel: int = 2, category: Type[Warning] = DeprecationWarning): +def deprecate_function( + msg: str, + stacklevel: int = 2, + category: Type[Warning] = DeprecationWarning, + modify_docstring: bool = True, + since: str = None, +): """Emit a warning prior to calling decorated function. Args: msg: Warning message to emit. - stacklevel: The warning stackevel to use, defaults to 2. + stacklevel: The warning stacklevel to use, defaults to 2. category: warning category, defaults to DeprecationWarning + modify_docstring: docstring box will be added. Default: True + since: If a version number, extends the docstring with a deprecation warning + box. If `modify_docstring == True`, then mandatory Returns: Callable: The decorated, deprecated callable. """ def decorator(func): + if modify_docstring and since is None: + # TODO: replace with: raise QiskitError( + warnings.warn( + "Adding a 'deprecated' directive to the docstring needs a version. Add parameter `since`" + " to `deprecate_function` or disable docstring annotation with `modify_docstring=False`." + " This warning will be a QiskitError exception in qiskit-terra 0.23.", + stacklevel=4, + category=FutureWarning, + ) + + if modify_docstring: + func.__doc__ = "\n".join( + _extend_docstring( + func, since or "unknown_version", {None: msg.expandtabs().splitlines()} + ) + ) + @functools.wraps(func) def wrapper(*args, **kwargs): warnings.warn(msg, category=category, stacklevel=stacklevel) @@ -77,3 +122,77 @@ def _rename_kwargs(func_name, kwargs, kwarg_map, category: Type[Warning] = Depre ) kwargs[new_arg] = kwargs.pop(old_arg) + + +def _extend_docstring(func, version, kwarg_map): + """kwarg_map[None] means message in no kwarg, and it will be + appended to the long description""" + docstr = func.__doc__ + if docstr: + docstr_lines = docstr.expandtabs().splitlines() + else: + docstr_lines = ["DEPRECATED"] + + # Mostly based on: + # https://peps.python.org/pep-0257/#handling-docstring-indentation + # --v-v-v-v-v-v-v-- + indent = 1000 + pre_args_line = None + for line_no, line in enumerate(docstr_lines[1:], start=1): + stripped = line.lstrip() + if stripped: + indent = min(indent, len(line) - len(stripped)) + if line.lstrip() == "Args:" and pre_args_line is None: + pre_args_line = line_no - 1 + if pre_args_line is None: + pre_args_line = len(docstr_lines) + spaces = "" + if indent != 1000: + spaces = " " * indent + # --^-^-^-^-^-^-^-- + + new_doc_str_lines = docstr_lines[:pre_args_line] + if None in kwarg_map: + new_doc_str_lines += ["", spaces + f".. deprecated:: {version}"] + for msg_line in kwarg_map[None]: + new_doc_str_lines.append(spaces + " " + msg_line) + + arg_indent = indent + args_section = False + deprecated_arg = False + for docstr_line in docstr_lines[pre_args_line:]: + stripped = docstr_line.lstrip() + current_indent = len(docstr_line) - len(stripped) + if args_section: + if deprecated_arg and current_indent == arg_indent: + new_doc_str_lines.append(docstr_line) + deprecated_arg = False + else: + old_arg_match = identifier.match(stripped) + if old_arg_match: + old_arg = old_arg_match[0] + new_arg = kwarg_map.get(old_arg) + if new_arg: + arg_indent = len(docstr_line) - len(stripped) + deprecated_arg = True + spaces = " " * arg_indent + new_doc_str_lines.append(docstr_line.split(": ")[0] + ":") + spaces += " " * 4 + new_doc_str_lines += [ + spaces + f".. deprecated:: {version}", + spaces + f" The keyword argument ``{old_arg}`` is deprecated.", + spaces + f" Please, use ``{new_arg}`` instead.", + "", + ] + else: + new_doc_str_lines.append(docstr_line) + else: + new_doc_str_lines.append(docstr_line) + else: + new_doc_str_lines.append(docstr_line) + if docstr_line.lstrip() == "Args:": + args_section = True + if args_section and len(docstr_line.lstrip()) == arg_indent: + args_section = False + + return new_doc_str_lines diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py index 94b758aed73..a8383e44d34 100644 --- a/qiskit/visualization/state_visualization.py +++ b/qiskit/visualization/state_visualization.py @@ -35,7 +35,7 @@ from .exceptions import VisualizationError -@deprecate_arguments({"rho": "state"}) +@deprecate_arguments({"rho": "state"}, since="0.15.1") @_optionals.HAS_MATPLOTLIB.require_in_call def plot_state_hinton( state, title="", figsize=None, ax_real=None, ax_imag=None, *, rho=None, filename=None @@ -250,7 +250,7 @@ def plot_bloch_vector(bloch, title="", ax=None, figsize=None, coord_type="cartes return None -@deprecate_arguments({"rho": "state"}) +@deprecate_arguments({"rho": "state"}, since="0.15.1") @_optionals.HAS_MATPLOTLIB.require_in_call def plot_bloch_multivector( state, title="", figsize=None, *, rho=None, reverse_bits=False, filename=None @@ -338,7 +338,7 @@ def plot_bloch_multivector( return fig.savefig(filename) -@deprecate_arguments({"rho": "state"}) +@deprecate_arguments({"rho": "state"}, since="0.15.1") @_optionals.HAS_MATPLOTLIB.require_in_call def plot_state_city( state, @@ -595,7 +595,7 @@ def plot_state_city( return fig.savefig(filename) -@deprecate_arguments({"rho": "state"}) +@deprecate_arguments({"rho": "state"}, since="0.15.1") @_optionals.HAS_MATPLOTLIB.require_in_call def plot_state_paulivec( state, title="", figsize=None, color=None, ax=None, *, rho=None, filename=None @@ -761,7 +761,7 @@ def phase_to_rgb(complex_number): return rgb -@deprecate_arguments({"rho": "state"}) +@deprecate_arguments({"rho": "state"}, since="0.15.1") @_optionals.HAS_MATPLOTLIB.require_in_call @_optionals.HAS_SEABORN.require_in_call def plot_state_qsphere( diff --git a/test/python/algorithms/time_evolvers/test_pvqd.py b/test/python/algorithms/time_evolvers/test_pvqd.py index 70cb12520e8..55c7c0f45ba 100644 --- a/test/python/algorithms/time_evolvers/test_pvqd.py +++ b/test/python/algorithms/time_evolvers/test_pvqd.py @@ -18,7 +18,7 @@ from ddt import data, ddt, unpack from qiskit import QiskitError -from qiskit.algorithms.evolvers import EvolutionProblem +from qiskit.algorithms.time_evolvers import TimeEvolutionProblem from qiskit.algorithms.optimizers import L_BFGS_B, SPSA, GradientDescent, OptimizerResult from qiskit.algorithms.state_fidelities import ComputeUncompute from qiskit.algorithms.time_evolvers.pvqd import PVQD @@ -96,7 +96,9 @@ def test_pvqd(self, hamiltonian_type, gradient, num_timesteps): optimizer=optimizer, num_timesteps=num_timesteps, ) - problem = EvolutionProblem(hamiltonian, time, aux_operators=[hamiltonian, self.observable]) + problem = TimeEvolutionProblem( + hamiltonian, time, aux_operators=[hamiltonian, self.observable] + ) result = pvqd.evolve(problem) self.assertTrue(len(result.fidelities) == 3) @@ -176,7 +178,7 @@ def test_invalid_num_timestep(self): optimizer=L_BFGS_B(), num_timesteps=0, ) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.01, aux_operators=[self.hamiltonian, self.observable] ) @@ -199,7 +201,7 @@ def test_initial_guess_and_observables(self): num_timesteps=10, initial_guess=initial_guess, ) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.1, aux_operators=[self.hamiltonian, self.observable] ) @@ -211,7 +213,7 @@ def test_initial_guess_and_observables(self): def test_zero_parameters(self): """Test passing an ansatz with zero parameters raises an error.""" - problem = EvolutionProblem(self.hamiltonian, time=0.02) + problem = TimeEvolutionProblem(self.hamiltonian, time=0.02) sampler = Sampler() fidelity_primitive = ComputeUncompute(sampler) @@ -230,7 +232,7 @@ def test_initial_state_raises(self): initial_state = QuantumCircuit(2) initial_state.x(0) - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.02, initial_state=initial_state, @@ -252,7 +254,7 @@ def test_initial_state_raises(self): def test_aux_ops_raises(self): """Test passing auxiliary operators with no estimator raises an error.""" - problem = EvolutionProblem( + problem = TimeEvolutionProblem( self.hamiltonian, time=0.02, aux_operators=[self.hamiltonian, self.observable] ) @@ -321,7 +323,7 @@ def test_gradient_supported(self): estimator=estimator, optimizer=optimizer, ) - problem = EvolutionProblem(self.hamiltonian, time=0.01) + problem = TimeEvolutionProblem(self.hamiltonian, time=0.01) for circuit, expected_support in tests: with self.subTest(circuit=circuit, expected_support=expected_support): pvqd.ansatz = circuit diff --git a/test/python/utils/test_deprecation.py b/test/python/utils/test_deprecation.py new file mode 100644 index 00000000000..3dbfcf87f4b --- /dev/null +++ b/test/python/utils/test_deprecation.py @@ -0,0 +1,232 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Tests for the methods in ``utils.deprecation``.""" + + +from qiskit import QiskitError +from qiskit.utils.deprecation import deprecate_function, deprecate_arguments +from qiskit.test import QiskitTestCase + + +class DummyClass: + """This is short description. Let's make it + multiline""" + + def __init__(self, arg1: int = None, arg2: [int] = None): + self.arg1 = arg1 + self.arg2 = arg2 + + @deprecate_function( + "The DummyClass.foo() method is being deprecated. Use the DummyClass.some_othermethod()", + since="1.2.3", + ) + def foo_deprecated(self, index_arg2: int): + """A multi-line + docstring. + + Here are more details. + + Args: + index_arg2: `index_arg2` description + + Returns: + int: returns `arg2[index_arg2]` + + Raises: + QiskitError: if `len(self.arg2) < index_arg2` + """ + if len(self.arg2) < index_arg2: + raise QiskitError("there is an error") + return self.arg2[index_arg2] + + @deprecate_arguments({"if_arg1": "other_if_arg1"}, since="1.2.3") + def bar_with_deprecated_arg( + self, if_arg1: int = None, index_arg2: int = None, other_if_arg1: int = None + ): + """ + A multi-line short + docstring. + + This is the long description + + Args: + if_arg1: `if_arg1` description + index_arg2: `index_arg2` description + other_if_arg1: `other_if_arg1` description + + Returns: + int or None: if `if_arg1 == self.arg1`, returns `arg2[index_arg2]` + """ + if other_if_arg1 == self.arg1 or if_arg1 == self.arg1: + return self.arg2[index_arg2] + return None + + +class TestDeprecationDummyClassRaise(QiskitTestCase): + """Test deprecation decorators raise warning.""" + + def assertDeprecationWarning(self, warn, expected_msg): + """Checks there only one exception and `expected_msg` is the message""" + self.assertEqual(len(warn.warnings), 1) + self.assertEqual(len(warn.warnings[0].message.args), 1) + self.assertEqual(warn.warnings[0].message.args[0], expected_msg) + + def test_raise_deprecate_function(self): + """Test deprecate_function raises.""" + + dummy = DummyClass(arg2=[1, 2, 3]) + with self.assertWarns(DeprecationWarning) as warn: + output = dummy.foo_deprecated(0) + self.assertDeprecationWarning( + warn, + "The DummyClass.foo() method is being deprecated. Use the DummyClass.some_othermethod()", + ) + self.assertEqual(output, 1) + + def test_raise_deprecate_arguments(self): + """Test deprecate_arguments raises.""" + + dummy = DummyClass(arg1=3, arg2=[1, 2, 3]) + with self.assertWarns(DeprecationWarning) as warn: + output = dummy.bar_with_deprecated_arg(if_arg1=3, index_arg2=0) + self.assertDeprecationWarning( + warn, + "bar_with_deprecated_arg keyword argument if_arg1 is deprecated and replaced" + " with other_if_arg1.", + ) + self.assertEqual(output, 1) + + +class TestDeprecationDummyClassDocstring(QiskitTestCase): + """Test deprecation decorators docstring modification for DummyClass.""" + + def test_dummyclass_deprecate_function(self): + """Test deprecate_function docstring.""" + + dummy = DummyClass() + deprecated_docstring = dummy.foo_deprecated.__doc__ + expected = """A multi-line + docstring. + + Here are more details. + + .. deprecated:: 1.2.3 + The DummyClass.foo() method is being deprecated. Use the DummyClass.some_othermethod() + + Args: + index_arg2: `index_arg2` description + + Returns: + int: returns `arg2[index_arg2]` + + Raises: + QiskitError: if `len(self.arg2) < index_arg2` + """ + self.assertEqual(deprecated_docstring, expected) + + def test_dummayclass_deprecate_arguments(self): + """Test deprecate_arguments docstring for DummyClass.""" + + dummy = DummyClass() + deprecated_docstring = dummy.bar_with_deprecated_arg.__doc__ + expected = """ + A multi-line short + docstring. + + This is the long description + + Args: + if_arg1: + .. deprecated:: 1.2.3 + The keyword argument ``if_arg1`` is deprecated. + Please, use ``other_if_arg1`` instead. + + index_arg2: `index_arg2` description + other_if_arg1: `other_if_arg1` description + + Returns: + int or None: if `if_arg1 == self.arg1`, returns `arg2[index_arg2]` + """ + self.assertEqual(deprecated_docstring, expected) + + +class TestDeprecationDocstring(QiskitTestCase): + """Test for docstring modification with several corner cases""" + + def test_deprecate_arguments_with_empty_lines(self): + """Test deprecate_arguments docstring with empty lines.""" + + def a_function(arg1, arg2, arg3): # pylint: disable=unused-argument, missing-type-doc + """ + This is a description. + + Args: + arg1: text. + text. + + more text + arg2: text + arg3: text + """ + pass + + deprecated_docstring = deprecate_arguments({"arg2": "arg3"}, since="1.2.3")( + a_function + ).__doc__ + expected = """ + This is a description. + + Args: + arg1: text. + text. + + more text + arg2: + .. deprecated:: 1.2.3 + The keyword argument ``arg2`` is deprecated. + Please, use ``arg3`` instead. + + arg3: text + """ + self.assertEqual(deprecated_docstring, expected) + + def test_deprecate_arguments_with_types(self): + """Test deprecate_arguments docstring with type docs.""" + + def a_function(arg1, arg2, arg3): # pylint: disable=unused-argument + """ + This is a description. + + Args: + arg1 (int): text + arg2 (str): text + arg3 (str): text + """ + pass + + deprecated_docstring = deprecate_arguments({"arg2": "arg3"}, since="1.2.3")( + a_function + ).__doc__ + expected = """ + This is a description. + + Args: + arg1 (int): text + arg2 (str): + .. deprecated:: 1.2.3 + The keyword argument ``arg2`` is deprecated. + Please, use ``arg3`` instead. + + arg3 (str): text + """ + self.assertEqual(deprecated_docstring, expected)