diff options
author | Eric Larson <larson.eric.d@gmail.com> | 2020-05-22 12:36:33 -0400 |
---|---|---|
committer | Eric Larson <larson.eric.d@gmail.com> | 2020-05-22 12:45:51 -0400 |
commit | ccc2427f8f3d5d7605c822b6143cfbc8058c0f3c (patch) | |
tree | dfc1b4e82e0ad632a0e87b3f3dd1a6565cf43e2c | |
parent | 78593a1059f0a9c04385f97b2c1caa221efefa5f (diff) | |
download | numpy-ccc2427f8f3d5d7605c822b6143cfbc8058c0f3c.tar.gz |
BUG: Indentation for docstrings
-rw-r--r-- | numpy/lib/tests/test_utils.py | 20 | ||||
-rw-r--r-- | numpy/lib/utils.py | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py index c96bf795a..261cfef5d 100644 --- a/numpy/lib/tests/test_utils.py +++ b/numpy/lib/tests/test_utils.py @@ -49,7 +49,7 @@ def old_func5(self, x): Bizarre indentation. """ return x -new_func5 = deprecate(old_func5) +new_func5 = deprecate(old_func5, message="This function is\ndeprecated.") def old_func6(self, x): @@ -74,10 +74,20 @@ def test_deprecate_fn(): @pytest.mark.skipif(sys.flags.optimize == 2, reason="-OO discards docstrings") -def test_deprecate_help_indentation(): - _compare_docs(old_func4, new_func4) - _compare_docs(old_func5, new_func5) - _compare_docs(old_func6, new_func6) +@pytest.mark.parametrize('old_func, new_func', [ + (old_func4, new_func4), + (old_func5, new_func5), + (old_func6, new_func6), +]) +def test_deprecate_help_indentation(old_func, new_func): + _compare_docs(old_func, new_func) + # Ensure we don't mess up the indentation + for knd, func in (('old', old_func), ('new', new_func)): + for li, line in enumerate(func.__doc__.split('\n')): + if li == 0: + assert line.startswith(' ') or not line.startswith(' '), knd + elif line: + assert line.startswith(' '), knd def _compare_docs(old_func, new_func): diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f233c7240..ba8616aa3 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1,5 +1,6 @@ import os import sys +import textwrap import types import re import warnings @@ -117,6 +118,7 @@ class _Deprecate: break skip += len(line) + 1 doc = doc[skip:] + depdoc = textwrap.indent(depdoc, ' ' * indent) doc = '\n\n'.join([depdoc, doc]) newfunc.__doc__ = doc try: |