Skip to content

Commit

Permalink
Backport PR #678: fix: deprecated decorator wasn't returning the valu…
Browse files Browse the repository at this point in the history
…e of the moved cal… (#678)

* fix: deprecated decorator wasn't returning the value of the moved callable.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* fix: update test to check that the decorator is returning

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

* docs: add changelog entry

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>

---------

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
victorgarcia98 authored and Flix6x committed May 12, 2023
1 parent a5cd475 commit 2a809c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion documentation/changelog.rst
Expand Up @@ -3,6 +3,13 @@
FlexMeasures Changelog
**********************

v0.13.1 | May XX, 2023
=======================
Bugfixes
---------
* `@deprecated` not returning the output of the decorated function [see `PR #678 <https://www.github.com/FlexMeasures/flexmeasures/pull/678>`_]


v0.13.0 | May 1, 2023
============================

Expand All @@ -14,7 +21,7 @@ v0.13.0 | May 1, 2023

.. warning:: Upgrading to this version requires running ``flexmeasures db upgrade`` (you can create a backup first with ``flexmeasures db-ops dump``).

.. note:: Read more on these features on `the FlexMeasures blog <https://flexmeasures.io/013-overlay-charts/>`__.
.. note:: Read more on these features on `the FlexMeasures blog <https://flexmeasures.io/013-overlay-charts/>`__.

New features
-------------
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/coding_utils.py
Expand Up @@ -165,7 +165,7 @@ def wrapper(*args, **kwargs):
f"The method or function {func.__name__} is deprecated and it is expected to be sunset in version {version}. Please, switch to using {inspect.getmodule(alternative).__name__}:{alternative.__name__} to suppress this warning."
)

func(*args, **kwargs)
return func(*args, **kwargs)

return wrapper

Expand Down
10 changes: 7 additions & 3 deletions flexmeasures/utils/tests/test_coding_utils.py
Expand Up @@ -2,19 +2,19 @@


def other_function():
pass
return 1


def test_deprecated_decorator(caplog, app):

# defining a function that is deprecated
@deprecated(other_function, "v14")
def deprecated_function():
pass
return other_function()

caplog.clear()

deprecated_function() # calling a deprecated function
value = deprecated_function() # calling a deprecated function
print(caplog.records)
assert len(caplog.records) == 1 # only 1 warning being printed

Expand All @@ -25,3 +25,7 @@ def deprecated_function():
assert "v14" in str(
caplog.records[0].message
) # checking that the message is correct

assert (
value == 1
) # check that the decorator is returning the value of `other_function`

0 comments on commit 2a809c6

Please sign in to comment.