-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
AttributeError assigning __annotations__ on read-only class #8883
Labels
Milestone
Comments
I confirm this issue with the code base of my customer. We have a special 'Const' class that doesn't allow for attributes to be changed. |
tk0miya
added a commit
to tk0miya/sphinx
that referenced
this issue
Feb 15, 2021
tk0miya
added a commit
that referenced
this issue
Feb 16, 2021
…nnotations Fix #8883: autodoc: AttributeError on assigning __annotations__
This was referenced Mar 7, 2021
This was referenced Mar 8, 2021
This was referenced Mar 16, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
I recently updated to sphinx 3.5.0 and I started seeing an
AttributeError
being raised when building on this line:sphinx/sphinx/ext/autodoc/__init__.py
Line 2432 in c60cc0c
Upon investigation it seems related to the area of #8799 which removed try/except around the assignment of
__annotations__
, though I think that code is new since the previous version anyway so that might be a bad lead.I'm not too familiar with python but it looks like it's possible to get
AttributeError
when assigning__annotations__
if the attribute isn't already there previously. In my case this class is imported from C (generated by swig) so I'm not sure if this is possible to replicate in pure python. Looking around it seems like if you set__slots__
then it will causeAttributeError
when adding new attributes, but as far as I could see on the sphinx side this code only runs on C created classes because I think native python class attributes will show up as properties, not attributes.To Reproduce
Unfortunately my project is not trivial to build since it requires C++. I've added the steps to reproduce the behavior on my project here, but if necessary I can set up a simple C project with no dependencies to reproduce:
If you want to make a fix and have me test it rather than repro'ing yourself, I'm happy to do that too.
Expected behavior
The documentation should build without throwing an exception, and handle this case where classes can't have new attributes added.
Your project
The sphinx project is available at https://github.com/baldurk/renderdoc under the 'docs' subdirectory, but as above it depends on the C++ project having built the python libraries.
Environment info
Additional context
I linked above the first failing CI run (after I revealed the actual exception that was previously hidden by mistake): https://github.com/baldurk/renderdoc/runs/1897925549?check_suite_focus=true
After forcing sphinx 3.4.0 when pip installing, it worked correctly: https://github.com/baldurk/renderdoc/runs/1897997876?check_suite_focus=true
Full exception log from a local build in a clean docker container
Let me know if you need any other information or a better repro case.
The text was updated successfully, but these errors were encountered: