Skip to content

Commit

Permalink
BREAK: issue deprecation warnings from deprecated module
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Dec 22, 2023
1 parent 843f3cd commit b63e9b5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ filterwarnings = [
"error",
"ignore:.*invalid value encountered in sqrt.*:RuntimeWarning",
"ignore:.*is deprecated and slated for removal in Python 3.14:DeprecationWarning",
"ignore:.*the @ampform.sympy.unevaluated_expression decorator instead( with commutative=True)?:DeprecationWarning",
"ignore:Passing a schema to Validator.iter_errors is deprecated.*:DeprecationWarning",
"ignore:The .* argument to NotebookFile is deprecated.*:pytest.PytestRemovedIn8Warning",
"ignore:The distutils package is deprecated.*:DeprecationWarning",
Expand Down
45 changes: 44 additions & 1 deletion src/ampform/sympy/deprecated.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""Deprecated classes and functions for constructing unevaluated expressions."""
"""Deprecated classes and functions for constructing unevaluated expressions.
.. deprecated:: 0.15.0
"""

from __future__ import annotations

import functools
from abc import abstractmethod
from typing import TYPE_CHECKING, Callable, TypeVar
from warnings import warn

import sympy as sp

Expand Down Expand Up @@ -45,6 +49,15 @@ class UnevaluatedExpression(sp.Expr):
_name: str | None
"""Optional instance attribute that can be used in LaTeX representations."""

def __init_subclass__(cls, **kwargs):
warn(
f"{cls.__name__} is deprecated, use the"
" @ampform.sympy.unevaluated_expression decorator instead",
category=DeprecationWarning,
stacklevel=1,
)
super().__init_subclass__(**kwargs)

def __new__(
cls: type[DecoratedClass],
*args,
Expand Down Expand Up @@ -144,6 +157,12 @@ def implement_expr(
Implement a :meth:`~object.__new__` and :meth:`~sympy.core.basic.Basic.doit` method
for a class that derives from `~sympy.core.expr.Expr` (via `UnevaluatedExpression`).
"""
warn(

Check warning on line 160 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L160

Added line #L160 was not covered by tests
"@implement_expr is deprecated, use the @ampform.sympy.unevaluated_expression"
" decorator instead",
category=DeprecationWarning,
stacklevel=1,
)

def decorator(

Check warning on line 167 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L167

Added line #L167 was not covered by tests
decorated_class: type[DecoratedClass],
Expand All @@ -162,6 +181,12 @@ def implement_new_method(
Implement a :meth:`~object.__new__` method for a class that derives from
`~sympy.core.expr.Expr` (via `UnevaluatedExpression`).
"""
warn(

Check warning on line 184 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L184

Added line #L184 was not covered by tests
"@implement_new_method is deprecated, use the"
" @ampform.sympy.unevaluated_expression decorator instead",
category=DeprecationWarning,
stacklevel=1,
)

def decorator(

Check warning on line 191 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L191

Added line #L191 was not covered by tests
decorated_class: type[DecoratedClass],
Expand Down Expand Up @@ -198,6 +223,12 @@ def implement_doit_method(
:meth:`~.UnevaluatedExpression.evaluate` method in the sense that it can work
recursively on deeper expression trees.
"""
warn(

Check warning on line 226 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L226

Added line #L226 was not covered by tests
"@implement_doit_method is deprecated, use the"
" @ampform.sympy.unevaluated_expression decorator instead",
category=DeprecationWarning,
stacklevel=1,
)

@functools.wraps(decorated_class.doit) # type: ignore[attr-defined]
def doit_method(self: UnevaluatedExpression, deep: bool = True) -> sp.Expr:
Expand All @@ -221,6 +252,12 @@ def make_commutative(
.. seealso:: :doc:`sympy:guides/assumptions`
"""
warn(

Check warning on line 255 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L255

Added line #L255 was not covered by tests
"@make_commutative is deprecated, use the @ampform.sympy.unevaluated_expression"
" decorator instead with commutative=True",
category=DeprecationWarning,
stacklevel=1,
)
decorated_class.is_commutative = True # type: ignore[attr-defined]
decorated_class.is_extended_real = True # type: ignore[attr-defined]
return decorated_class

Check warning on line 263 in src/ampform/sympy/deprecated.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/sympy/deprecated.py#L261-L263

Added lines #L261 - L263 were not covered by tests
Expand All @@ -234,6 +271,12 @@ def create_expression(
**kwargs,
) -> DecoratedExpr:
"""Helper function for implementing `UnevaluatedExpression.__new__`."""
warn(
"create_expression() is deprecated, construct the class with the"
" @ampform.sympy.unevaluated_expression decorator instead",
category=DeprecationWarning,
stacklevel=1,
)
args = sp.sympify(args)
if issubclass(cls, UnevaluatedExpression):
expr = UnevaluatedExpression.__new__(cls, *args, name=name, **kwargs)
Expand Down

0 comments on commit b63e9b5

Please sign in to comment.