-
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
Intersphinx: py:class reference target not found: _io.BytesIO #12867
Comments
I'm making an educated guess that something goes wrong when you try to display the inheritance because that implies linking to the Python standard library and the error message seems to suggest there's some magic under the hood (as is hinted by the unexpected change from a public
Did you try getting rid of .. autoclass:: PIL.AppendingTiffWriter
:show-inheritance: another alternative would be hardcoding the fully qualified name in autodoc, like: .. autoclass:: PIL.AppendingTiffWriter(io.BytesIO) Anyway, I checked your intersphinx and it seems alright. When one of these problems happens the surest workaround (generally happens to me with def add_superclass(app, name, obj, options, bases):
"""Used to add a superclass (or metaclass) to the bases of a class."""
from your_module import your_super_class
if name == "your_module.your_subclass":
bases.append(your_super_class)
def setup(app):
app.connect("autodoc-process-bases", add_superclass) As to what causes these things? Who's to say...?! Your MRE seems alright to me. |
Removing |
I agree. I don't contribute fixes for Sphinx's internals and this issue is beyond my knowledge of the internals. But of the 3 workaround alternatives using the |
I didn't mean change the Python code. I meant write the fully qualified name directly into the autodoc declaration parenthesis so that the cross-reference gets resolved without checking the run-time imported .. autoclass:: PIL.AppendingTiffWriter(io.BytesIO)
:show-inheritance: I checked the uncompiled
So all 3 methods should resolve it. |
You're right, sorry, I misread that. My own workaround was simply But I had imagined that either If the considered opinion of the sphinx community is that this is just how things are though, that's... unexpected, but thanks for your time. |
Hi Andrew, Thank you for writing this up, I agree it is a bug, and I imagine probably because Sphinx is resolving the type at runtime to the builtin _io extension module rather than the public io module. I haven't tested this, though. The simplest way to resolve this is probably a map of overrides, though ugly. It is interesting that it only manifests with :show-inheritance:, though. A |
I guess it's something non standard in Python's
I personally prefer the alternatives I've shown but using There's an additional problem to using nitpick_ignore = [("py:class", "_io.BytesIO")] because you're silencing other potential problems with
If it gets the job done it's better to get an easy interim solution until something more durable is thought of. |
Actually, I have less time to work on autodoc. I don't know when I'll have time. I had in mind some improvements for If I recall correctly, here's the actual flow:
One way to fix it is to pre-process nodes before calling the reference resolver. This can be done by remapping fully-qualified names into names that are known to exist. I had something locally setup for that but I'm not sure it's universal enough. In addition the implementation depends on various other utilities that I implemented so I'm not even sure I can bundle it as a standalone fix. |
This might actually be a CPython problem, googling for the generic error message generally leads to https://bugs.python.org/issue11975 so maybe they should adjust their index for |
Describe the bug
It appears to me that intersphinx is unable to create a link to
BytesIO
when a class inherits from it.How to Reproduce
I've created a minimal reproduction at https://github.com/radarhere/sphinx_demo. The build can be triggered using GitHub Actions. See https://github.com/radarhere/sphinx_demo/actions/runs/10748344237 for full output.
Environment Information
Sphinx extensions
Additional context
No response
The text was updated successfully, but these errors were encountered: