Skip to content

Commit 8a066c0

Browse files
committed
DOC: Truncate docstrings of expired functions
This makes the expiration more obvious than a single line at the end, as well as prevents doctests from raising ExpiredDeprecationErrors
1 parent 1b05c0f commit 8a066c0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

nibabel/deprecator.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,18 @@ def deprecated_func(*args, **kwargs):
182182
warnings.warn(message, warn_class, stacklevel=2)
183183
return func(*args, **kwargs)
184184

185-
deprecated_func.__doc__ = _add_dep_doc(deprecated_func.__doc__,
186-
message, TESTSETUP, TESTCLEANUP)
185+
keep_doc = deprecated_func.__doc__
186+
setup = TESTSETUP
187+
cleanup = TESTCLEANUP
188+
# After expiration, remove all but the first paragraph.
189+
# The details are no longer relevant, but any code will likely
190+
# raise exceptions we don't need.
191+
if keep_doc and until and self.is_bad_version(until):
192+
lines = '\n'.join(line.rstrip() for line in keep_doc.splitlines())
193+
keep_doc = lines.split('\n\n', 1)[0]
194+
setup = ''
195+
cleanup = ''
196+
deprecated_func.__doc__ = _add_dep_doc(keep_doc, message, setup, cleanup)
187197
return deprecated_func
188198

189199
return deprecator

nibabel/tests/test_deprecator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ def test_dep_func(self):
111111
'foo\n\n* deprecated from version: 1.2\n* Raises '
112112
f'{ExpiredDeprecationError} as of version: 1.8\n')
113113
func = dec('foo', '1.2', '1.8')(func_doc_long)
114-
assert (func.__doc__ ==
115-
'A docstring\n \n foo\n \n * deprecated from version: 1.2\n '
116-
f'* Raises {ExpiredDeprecationError} as of version: 1.8\n \n'
117-
f'{indent(TESTSETUP, " ", lambda x: True)}'
118-
f' Some text\n{indent(TESTCLEANUP, " ", lambda x: True)}')
114+
assert func.__doc__ == f"""\
115+
A docstring
116+
117+
foo
118+
119+
* deprecated from version: 1.2
120+
* Raises {ExpiredDeprecationError} as of version: 1.8
121+
"""
119122
with pytest.raises(ExpiredDeprecationError):
120123
func()
121124

0 commit comments

Comments
 (0)