From 08290d619e05e972d597d0b2fe084029d0e723d5 Mon Sep 17 00:00:00 2001 From: Sam Morley-Short Date: Mon, 13 Apr 2026 15:47:43 +0100 Subject: [PATCH 1/3] Use FutureWarning for deprecations --- src/bartiq/compilation/preprocessing.py | 3 ++- src/bartiq/symbolics/sympy_backend.py | 2 +- src/bartiq/symbolics/sympy_interpreter.py | 2 +- tests/compilation/test_preprocessing.py | 17 ++++++++++++++++- tests/symbolics/test_sympy_backend.py | 2 +- tests/symbolics/test_sympy_interpreter.py | 4 ++-- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/bartiq/compilation/preprocessing.py b/src/bartiq/compilation/preprocessing.py index f01622ed..0e4b22ee 100644 --- a/src/bartiq/compilation/preprocessing.py +++ b/src/bartiq/compilation/preprocessing.py @@ -43,7 +43,8 @@ def propagate_child_resources(routine: Routine[T], backend: SymbolicBackend[T]) """ warnings.warn( "Usage of propagate_child_resources has been deprecated, as this is now handled" "directly in the compilation.", - DeprecationWarning, + FutureWarning, + stacklevel=2, ) child_additive_resources_map: defaultdict[str, set[str]] = defaultdict(set) child_multiplicative_resources_map: defaultdict[str, set[str]] = defaultdict(set) diff --git a/src/bartiq/symbolics/sympy_backend.py b/src/bartiq/symbolics/sympy_backend.py index ab4c233c..1bc9c59a 100644 --- a/src/bartiq/symbolics/sympy_backend.py +++ b/src/bartiq/symbolics/sympy_backend.py @@ -218,7 +218,7 @@ def value_of(self, value: TExpr[Expr]) -> TExpr[Expr]: warn( "The value_of method is deprecated. The SympyBackend now returns native numbers from all relevant " "functions", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return _attempt_numeric_evaluation(value) diff --git a/src/bartiq/symbolics/sympy_interpreter.py b/src/bartiq/symbolics/sympy_interpreter.py index 949ed60e..34b0c8b4 100644 --- a/src/bartiq/symbolics/sympy_interpreter.py +++ b/src/bartiq/symbolics/sympy_interpreter.py @@ -197,7 +197,7 @@ class nlz(ntz): def __new__(cls, n, *args, **kwargs): warnings.warn( "nlz is deprecated and will be removed in a future release; use ntz instead", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return super().__new__(cls, n, *args, **kwargs) diff --git a/tests/compilation/test_preprocessing.py b/tests/compilation/test_preprocessing.py index 327fd975..5064dfbb 100644 --- a/tests/compilation/test_preprocessing.py +++ b/tests/compilation/test_preprocessing.py @@ -1,8 +1,10 @@ +import warnings + import pytest from qref.schema_v1 import RoutineV1 from bartiq._routine import Routine, routine_to_qref -from bartiq.compilation.preprocessing import PreprocessingStage, propagate_linked_params +from bartiq.compilation.preprocessing import PreprocessingStage, propagate_child_resources, propagate_linked_params def _apply_stage(qref_obj: RoutineV1, stage: PreprocessingStage, backend) -> RoutineV1: @@ -128,3 +130,16 @@ def test_precompile_propagates_linked_params(input_dict, expected_linked_params, routine = routine.children[part] assert routine.linked_params == linked_params + + +def test_precompile_propagate_child_resources_emits_future_warning_with_caller_stacklevel(backend): + input_routine = Routine.from_qref(RoutineV1(name="root", type="dummy"), backend) + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + propagate_child_resources(input_routine, backend) + + assert len(caught) == 1 + warning = caught[0] + assert warning.category is FutureWarning + assert warning.filename == __file__ diff --git a/tests/symbolics/test_sympy_backend.py b/tests/symbolics/test_sympy_backend.py index a8930463..da3ad4ba 100644 --- a/tests/symbolics/test_sympy_backend.py +++ b/tests/symbolics/test_sympy_backend.py @@ -75,7 +75,7 @@ def test_value_of_returns_expr_if_numerical_evaluation_is_not_possible(): def test_value_of_raises_deprecation_warning(): - with pytest.warns(DeprecationWarning): + with pytest.warns(FutureWarning): assert sympy_backend.value_of(10) diff --git a/tests/symbolics/test_sympy_interpreter.py b/tests/symbolics/test_sympy_interpreter.py index 512ffdca..eb2481cd 100644 --- a/tests/symbolics/test_sympy_interpreter.py +++ b/tests/symbolics/test_sympy_interpreter.py @@ -502,7 +502,7 @@ def test_custom_max_evaluates_if_some_inputs_are_rationals(args, expected_max): ("max(x)", {"x": 0}, 0), ], ) -@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:DeprecationWarning") +@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:FutureWarning") def test_espressions_parsed_by_the_interpreter_are_directly_lambdifiable(expr, args, numeric_val): lambdified = lambdify(list(args.keys()), parse_to_sympy(expr)) @@ -522,7 +522,7 @@ def test_numerical_implementation_of_multiplicity_raises_when_one_of_arguments_i [(-1, ValueError), (-2, ValueError), (-2.5, TypeError), (-0.5, TypeError), (0.5, TypeError), (3.1, TypeError)], ) @pytest.mark.parametrize("func", ["nlz", "ntz"]) -@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:DeprecationWarning") +@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:FutureWarning") def test_numerical_implementations_of_ntz_and_nlz_raise_if_argument_isnt_nonnegative_int(n, error_cls, func): lambdified = lambdify(["n"], parse_to_sympy(f"{func}(n)")) From ca611f89513391d8f4f4a94b7a34836576b507d7 Mon Sep 17 00:00:00 2001 From: Sam Morley-Short Date: Mon, 13 Apr 2026 16:16:02 +0100 Subject: [PATCH 2/3] Remove preprocessing warning test --- tests/compilation/test_preprocessing.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/compilation/test_preprocessing.py b/tests/compilation/test_preprocessing.py index 5064dfbb..327fd975 100644 --- a/tests/compilation/test_preprocessing.py +++ b/tests/compilation/test_preprocessing.py @@ -1,10 +1,8 @@ -import warnings - import pytest from qref.schema_v1 import RoutineV1 from bartiq._routine import Routine, routine_to_qref -from bartiq.compilation.preprocessing import PreprocessingStage, propagate_child_resources, propagate_linked_params +from bartiq.compilation.preprocessing import PreprocessingStage, propagate_linked_params def _apply_stage(qref_obj: RoutineV1, stage: PreprocessingStage, backend) -> RoutineV1: @@ -130,16 +128,3 @@ def test_precompile_propagates_linked_params(input_dict, expected_linked_params, routine = routine.children[part] assert routine.linked_params == linked_params - - -def test_precompile_propagate_child_resources_emits_future_warning_with_caller_stacklevel(backend): - input_routine = Routine.from_qref(RoutineV1(name="root", type="dummy"), backend) - - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - propagate_child_resources(input_routine, backend) - - assert len(caught) == 1 - warning = caught[0] - assert warning.category is FutureWarning - assert warning.filename == __file__ From 60539ce7d3dcf2109dea98528485119d0c9ac5ac Mon Sep 17 00:00:00 2001 From: Sam Morley-Short Date: Fri, 17 Apr 2026 23:23:49 +0100 Subject: [PATCH 3/3] Revert "Use FutureWarning for deprecations" This reverts commit 08290d619e05e972d597d0b2fe084029d0e723d5. --- src/bartiq/compilation/preprocessing.py | 2 +- src/bartiq/symbolics/sympy_backend.py | 2 +- src/bartiq/symbolics/sympy_interpreter.py | 2 +- tests/symbolics/test_sympy_backend.py | 2 +- tests/symbolics/test_sympy_interpreter.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bartiq/compilation/preprocessing.py b/src/bartiq/compilation/preprocessing.py index 0e4b22ee..c299e968 100644 --- a/src/bartiq/compilation/preprocessing.py +++ b/src/bartiq/compilation/preprocessing.py @@ -43,7 +43,7 @@ def propagate_child_resources(routine: Routine[T], backend: SymbolicBackend[T]) """ warnings.warn( "Usage of propagate_child_resources has been deprecated, as this is now handled" "directly in the compilation.", - FutureWarning, + DeprecationWarning, stacklevel=2, ) child_additive_resources_map: defaultdict[str, set[str]] = defaultdict(set) diff --git a/src/bartiq/symbolics/sympy_backend.py b/src/bartiq/symbolics/sympy_backend.py index 1bc9c59a..ab4c233c 100644 --- a/src/bartiq/symbolics/sympy_backend.py +++ b/src/bartiq/symbolics/sympy_backend.py @@ -218,7 +218,7 @@ def value_of(self, value: TExpr[Expr]) -> TExpr[Expr]: warn( "The value_of method is deprecated. The SympyBackend now returns native numbers from all relevant " "functions", - FutureWarning, + DeprecationWarning, stacklevel=2, ) return _attempt_numeric_evaluation(value) diff --git a/src/bartiq/symbolics/sympy_interpreter.py b/src/bartiq/symbolics/sympy_interpreter.py index 34b0c8b4..949ed60e 100644 --- a/src/bartiq/symbolics/sympy_interpreter.py +++ b/src/bartiq/symbolics/sympy_interpreter.py @@ -197,7 +197,7 @@ class nlz(ntz): def __new__(cls, n, *args, **kwargs): warnings.warn( "nlz is deprecated and will be removed in a future release; use ntz instead", - FutureWarning, + DeprecationWarning, stacklevel=2, ) return super().__new__(cls, n, *args, **kwargs) diff --git a/tests/symbolics/test_sympy_backend.py b/tests/symbolics/test_sympy_backend.py index da3ad4ba..a8930463 100644 --- a/tests/symbolics/test_sympy_backend.py +++ b/tests/symbolics/test_sympy_backend.py @@ -75,7 +75,7 @@ def test_value_of_returns_expr_if_numerical_evaluation_is_not_possible(): def test_value_of_raises_deprecation_warning(): - with pytest.warns(FutureWarning): + with pytest.warns(DeprecationWarning): assert sympy_backend.value_of(10) diff --git a/tests/symbolics/test_sympy_interpreter.py b/tests/symbolics/test_sympy_interpreter.py index eb2481cd..512ffdca 100644 --- a/tests/symbolics/test_sympy_interpreter.py +++ b/tests/symbolics/test_sympy_interpreter.py @@ -502,7 +502,7 @@ def test_custom_max_evaluates_if_some_inputs_are_rationals(args, expected_max): ("max(x)", {"x": 0}, 0), ], ) -@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:FutureWarning") +@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:DeprecationWarning") def test_espressions_parsed_by_the_interpreter_are_directly_lambdifiable(expr, args, numeric_val): lambdified = lambdify(list(args.keys()), parse_to_sympy(expr)) @@ -522,7 +522,7 @@ def test_numerical_implementation_of_multiplicity_raises_when_one_of_arguments_i [(-1, ValueError), (-2, ValueError), (-2.5, TypeError), (-0.5, TypeError), (0.5, TypeError), (3.1, TypeError)], ) @pytest.mark.parametrize("func", ["nlz", "ntz"]) -@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:FutureWarning") +@pytest.mark.filterwarnings(r"ignore:nlz is deprecated:DeprecationWarning") def test_numerical_implementations_of_ntz_and_nlz_raise_if_argument_isnt_nonnegative_int(n, error_cls, func): lambdified = lambdify(["n"], parse_to_sympy(f"{func}(n)"))