Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/scverse_misc/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class Deprecation(str):
msg: The deprecation message.
"""

version_deprecated: LiteralString

def __new__(cls, version_deprecated: LiteralString, msg: LiteralString = "") -> LiteralString:
if not msg:
msg = "" # be lenient here, people don’t want to see “None” or “False” here
obj = super().__new__(cls, msg)
obj.version_deprecated = version_deprecated
return obj
Expand Down Expand Up @@ -56,7 +60,7 @@ def decorate(func: F) -> F:

doc = getdoc(func)
docmsg = f".. version-deprecated:: {msg.version_deprecated}"
if len(msg) is not None:
if len(msg):
docmsg += f"\n {msg}"
warnmsg += f" {msg}"

Expand Down
6 changes: 4 additions & 2 deletions tests/test_deprecation_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def func(foo, bar):
return 42

func.__doc__ = docstring
return deprecated(Deprecation("foo", msg))(func)
return deprecated(Deprecation("foo", msg or ""))(func)


def test_deprecation_decorator(deprecated_func, docstring, msg):
Expand All @@ -50,5 +50,7 @@ def test_deprecation_decorator(deprecated_func, docstring, msg):
assert lines[0] == lines_orig[0]
assert len(lines[1].strip()) == 0
assert lines[2].startswith(".. version-deprecated")
if msg is not None:
if msg is None:
assert len(lines) == 3 or not lines[3].startswith(" ")
else:
assert lines[3] == f" {msg}"
Loading