Skip to content

Fix AttributeError in underline length check #363

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 4 commits into from
Jan 26, 2022
Merged

Conversation

rossbar
Copy link
Contributor

@rossbar rossbar commented Jan 26, 2022

Fixes gh-362.

The NumpyDocString class raises a UserWarning during docstring parsing when the underline length doesn't match the header length. In an attempt to make this UserWarning more informative, some introspection is performed to try to get the name and location of the object. This introspection relied on the assumption that the object would have a __name__ attribute, which is not always the case, e.g. when _obj is an instance of a user-defined Callable.

This PR fixes the issue by only reporting the improved UserWarning message when the introspection is successful.

@larsoner larsoner merged commit f33a53e into numpy:main Jan 26, 2022
@larsoner
Copy link
Collaborator

Thanks @rossbar !

@ajschmidt8
Copy link

@larsoner, will this be included in a release soon? This fixes an error that we're seeing with our doc builds.

@rossbar
Copy link
Contributor Author

rossbar commented Feb 4, 2022

will this be included in a release soon? This fixes an error that we're seeing with our doc builds.

I'd be +1 for a patch release but we might want to wait a bit to see if any more bugs come up.

Fortunately, this particular exception is triggered by a Warning due to bad underline length for section headings, so fixing the docstring heading issue will also fix the exception. See e.g. statsmodels/statsmodels#8044, which was all that was required to fix the error that was originally reported in #362.

Your case should be similar; the trick will be finding which docstring hit the exception. If you look at the sphinx-build log, you should see something like:

Handler <function mangle_signature at 0x7f0833af8f70> for event 'autodoc-process-signature' threw an exception (exception: '<object_name>' object has no attribute '__name__')

or similar. If you look at the docstring for <object_name> you should be able to find the docstring section heading(s) with mismatched underline length. Fixing the heading underlining should be sufficient to avoid the exception.

@jarrodmillman jarrodmillman added this to the 1.2.1 milestone Mar 29, 2022
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.

BUG: 1.2 raises error w.r.t. object has no attribute '__name__'
4 participants