Skip to content

Clarify location of certain invalid docstrings. #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 27, 2019

Closes #115 Closes #123

If one adds the following invalid docstring at the end of
doc/example.py

def bar():
    """
    Parameters
    ----------
    a : int

    Parameters
    ----------
    b : float
    """

then as of numpydoc master the error message is

ValueError: The section Parameters appears twice in the docstring of None in None.

This patch fixes the error message to give

ValueError: The section Parameters appears twice in the docstring of <function bar at 0x7fa5c9d20e18> in /path/to/numpydoc/doc/example.py.

Initially noticed at matplotlib/matplotlib#11859 (comment).

If one adds the following invalid docstring at the end of
`doc/example.py`
```
def bar():
    """
    Parameters
    ----------
    a : int

    Parameters
    ----------
    b : float
    """
```
then as of numpydoc master the error message is
```
ValueError: The section Parameters appears twice in the docstring of None in None.
```

This patch fixes the error message to give
```
ValueError: The section Parameters appears twice in the docstring of <function bar at 0x7fa5c9d20e18> in /path/to/numpydoc/doc/example.py.
```
@jnothman
Copy link
Member

Does this fix #115? Is it superseding #123 Sorry I'm not investigating now

@anntzer
Copy link
Contributor Author

anntzer commented Jan 27, 2019

I think that it does fix #115 (well, there isn't a minimum repro for it but looks likely the same) which I didn't notice, and does so more simply than #123 by reusing the get_doc_info logic rather than reimplementing it all.

@jnothman
Copy link
Member

I agree it is simpler. Is it reasonable to add a test?

@anntzer
Copy link
Contributor Author

anntzer commented Jan 28, 2019

It's not so easy. I wrote

diff --git i/numpydoc/tests/test_main.py w/numpydoc/tests/test_main.py
index e565bb2..e0b1fb3 100644
--- i/numpydoc/tests/test_main.py
+++ w/numpydoc/tests/test_main.py
@@ -4,12 +4,14 @@ from contextlib import contextmanager
 import os
 import sys
 import tempfile
+import warnings
 try:
     from StringIO import StringIO
 except ImportError:
     from io import StringIO
 
 from numpydoc.__main__ import main
+import pytest
 
 
 PACKAGE_CODE = """
@@ -29,6 +31,17 @@ def foo(a, b=5):
     something_else
         bar
     '''
+
+def oops():
+    '''
+    Parameters
+    ----------
+    a : int
+
+    Parameters
+    ----------
+    b : float
+    '''
 """
 
 
@@ -72,6 +85,9 @@ def test_main():
     with _mock_module('somepackage1'):
         out = _capture_main('somepackage1.module.foo')
     assert out.startswith('Hello world\n')
+    with pytest.raises(ValueError, match='docstring of <function oops'):
+        with _mock_module('somepackage1'):
+            out = _capture_main('somepackage1.module.oops')
     with _mock_module('somepackage2'):
         out = _capture_main('somepackage2.module')
     assert out.startswith('This module has test')

which should have been a proper test, but that also works as of master because that tests numpydoc.main, which already uses get_doc_object; what really needs to be tested is that numpydoc.numpydoc.mangle_signature also uses get_doc_object but there's no test for mangle_signature at all right now (as noted by the comment "# TODO: does not currently check that numpydoc transformations are applied").

@jnothman jnothman merged commit 2cdd4d9 into numpy:master Apr 2, 2019
@anntzer anntzer deleted the invalid-docs-location branch April 2, 2019 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Location reporting returns useless information
3 participants