Skip to content

Commit

Permalink
Fix #34: versionadded and versionchanged decorators don't emi…
Browse files Browse the repository at this point in the history
…t ``DeprecationWarning`` anymore on decorated classes.
  • Loading branch information
tantale committed Dec 18, 2020
1 parent 68f22d4 commit a67bc54
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Fix

- Fix packit configuration: use ``upstream_tag_template: v{version}``.

- Fix #34: ``versionadded`` and ``versionchanged`` decorators don't emit ``DeprecationWarning``
anymore on decorated classes.


Other
-----
Expand Down
2 changes: 2 additions & 0 deletions deprecated/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def __call__(self, wrapped):
if reason:
docstring += " {reason}\n".format(reason=reason)
wrapped.__doc__ = docstring
if self.directive in {"versionadded", "versionchanged"}:
return wrapped
return super(SphinxAdapter, self).__call__(wrapped)


Expand Down
2 changes: 1 addition & 1 deletion docs/source/sphinx/calc_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def mean(values):
"""
Compute the arithmetic mean (“average”) of values.
:type values: list[float]
:type values: typing.List[float]
:param values: List of floats
:return: Mean of values.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/sphinx/calc_mean_deco.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def mean(values):
"""
Compute the arithmetic mean (“average”) of values.
:type values: list[float]
:type values: typing.List[float]
:param values: List of floats
:return: Mean of values.
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/source/sphinx_deco.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The documentation of the *mean()* function looks like this:
Compute the arithmetic mean (“average”) of values.
:type values: list[float]
:type values: typing.List[float]
:param values: List of floats
:return: Mean of values.
Expand Down
23 changes: 23 additions & 0 deletions tests/test_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
:return: sum = *x* + *y*
""",
],
ids=["no_docstring", "short_docstring", "long_docstring"]
)
def docstring(request):
return request.param
Expand Down Expand Up @@ -68,6 +69,7 @@ def directive(request):
),
),
],
ids=["reason&version", "version", "reason"]
)
def test_has_sphinx_docstring(docstring, directive, reason, version, expected):
# The function:
Expand All @@ -93,6 +95,16 @@ def foo(x, y):
if current:
assert re.search("\n[ ]*\n$", current, flags=re.DOTALL)

with warnings.catch_warnings(record=True) as warns:
foo(1, 2)

if directive in {'versionadded', 'versionchanged'}:
# don't emit DeprecationWarning
assert len(warns) == 0
else:
# emit DeprecationWarning
assert len(warns) == 1


# noinspection PyShadowingNames
@pytest.mark.skipif(
Expand Down Expand Up @@ -131,6 +143,7 @@ def foo(x, y):
),
),
],
ids=["reason&version", "version", "reason"]
)
def test_cls_has_sphinx_docstring(docstring, directive, reason, version, expected):
# The class:
Expand All @@ -156,6 +169,16 @@ class Foo(object):
if current:
assert re.search("\n[ ]*\n$", current, flags=re.DOTALL)

with warnings.catch_warnings(record=True) as warns:
Foo()

if directive in {'versionadded', 'versionchanged'}:
# don't emit DeprecationWarning
assert len(warns) == 0
else:
# emit DeprecationWarning
assert len(warns) == 1


class MyDeprecationWarning(DeprecationWarning):
pass
Expand Down

0 comments on commit a67bc54

Please sign in to comment.