Skip to content
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

NoneType attribute error 'name' #186

Closed
fmigneault opened this issue Dec 3, 2019 · 8 comments
Closed

NoneType attribute error 'name' #186

fmigneault opened this issue Dec 3, 2019 · 8 comments

Comments

@fmigneault
Copy link

Getting the following error when running sphinx's makefile with sphinx-autoapi>=1.2 during the autoapi generation steps.

Running the same command with sphinx-autoapi<1.2 doesn't generate this error.
Using sphinx 2.2.2, also reproduced on 2.0.1.

Exception occurred:
  File "[...]/lib/python3.7/site-packages/autoapi/mappers/python/astroid_utils.py", line 392, in _format_args
    argname = arg.name
AttributeError: 'NoneType' object has no attribute 'name'
The full traceback has been saved in /tmp/sphinx-err-0ri9fabe.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Makefile:54: recipe for target 'html' failed
make: *** [html] Error 2

Reference log of the error: sphinx.log

@AWhetter
Copy link
Collaborator

Thanks for the report! Are you able to figure out which bit of code was being parsed when this happened? It's unclear under what circumstances arg is allowed to be None.

@AWhetter
Copy link
Collaborator

If you up the verbosity of Sphinx's logging, it should tell you at least which file is being parsed (https://www.sphinx-doc.org/en/master/man/sphinx-build.html#cmdoption-sphinx-build-v).

@fmigneault
Copy link
Author

Hi, sorry for the delay. I up'd the verbosity, got the following: sphinx-verbose.log

The file corresponds to the following:
https://github.com/crim-ca/weaver/blob/17ed20140ec88f611406332df9c9f5d239eb6d54/weaver/datatype.py

I'm running make docs from the root of this repo, which in turns runs sphinx's make html with autoapi defined in its conf.py.

I tried with sphinx-autoapi==1.1.0 and I don't have the error encountered, so the problem happened in 1.2.x series.

Thanks for your help, hopefully you can pinpoint the source of the issue.

@AWhetter
Copy link
Collaborator

AWhetter commented Jan 7, 2020

The error is happening because the type annotation here (https://github.com/crim-ca/weaver/blob/17ed20140ec88f611406332df9c9f5d239eb6d54/weaver/datatype.py#L729) is incorrect. The Any needs to be prepended with **, as noted here (https://mypy.readthedocs.io/en/latest/python2.html#type-checking-python-2-code).
AutoAPI expects an extra argument to exist because there's a type annotation for it, but fails when it can't find it.

That being said, we could be doing a better job of handling this situation. I think raising a warning makes the most sense.

@fmigneault
Copy link
Author

@AWhetter
Wow! I never realized there was a different annotation method for single- vs multi-line typing...
Thanks for the pointer.

And yes, a small warning could help debugging such thing more easily in the future.
I might have a few code bases to update with this typing correction.

@fmigneault
Copy link
Author

@AWhetter
I replaced by # type: (ProcessWPS, **Any) -> Process but still getting the same error with 1.2.1.
It looks like astroid provides name="Any" in the annotation, but not in the arg in this case.

image

@AWhetter
Copy link
Collaborator

AWhetter commented Jan 8, 2020

You're right.
Unfortunately astroid doesn't support being able to distinguish between the type comments for regular arguments and for args/kwargs.
I've made another fix that's now in master that will fix this issue once and for all.

@fmigneault
Copy link
Author

I tried with the new commit, works great!
Thanks for the fix, will wait for a tag to update requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants