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
Handler autodoc throw exceptions after >= 7.1.0 release #11543
Comments
I was afraid that the cause was what I implemented for PEP 695 but it appears that the issue is with the default values. In particular, I suspect that |
The issue still exists even without |
Can you test with only built-in Sphinx extensions ? (only those in |
I have encountered the same warnings when creating docs for dataclasses. |
Ok, I confirm it. The issue stems from the fact that we cannot retrieve properly the function definition AST for a dataclass. Even this simple example fails: from __future__ import annotations
from dataclasses import dataclass
@dataclass
class Foo:
"""pouet"""
bar: int = 1 The reason is that we fail to extract the code source for |
I've bisected the culprit commit 4de540e which included some In particular, because we don't catch the assertion, it propagates. I'll write a patch for that today (and document why we are allowed to ignore the assertion!). |
In addition to dataclasses, a |
I tried applying the potential fix to jaraco/irc, but it introduced a new error not present in 7.1:
Perhaps that's by design, but it does mean that my best hope for a workaround until a proper fix is introduced will be to pin to |
This error is likely due to furo theme. We deprecated some theme API so it might be the reason (check the latest CHANGES). I'll try to understand why it fails with namedtuple in the upcoming days. EDIT: I don't know why what I did could affect themes btw. |
warnings after >= 7.1.0 release of sphinx - sphinx-doc/sphinx#11543
@jaraco I just saw that your error is coming from another function so it's likely an issue on furo. |
warnings after >= 7.1.0 release of sphinx - sphinx-doc/sphinx#11543
@AA-Turner I am still getting this issue (sphinx 7.2.2) for a very specific signature: Example: class Foo:
@classmethod
def foo(cls, bar, /, *, baz: int) -> None:
print(cls, bar, baz)
|
A |
@randolf-scholz sorry for the earlier note, I've found the error. In In your example this clearly fails, as The challenge comes to fixing this. To take this tortured but legal case: class Lobster:
@classmethod
def spam(cls, ham, *, eggs: int) -> None: # note: no '/'
print(cls, ham, eggs)
Lobster.spam(1, eggs=1)
# <class '__main__.Lobster'> 1 1
Lobster.spam.__get__(Lobster(), Lobster).__func__(cls=Lobster, ham=1, eggs=1)
# <class '__main__.Lobster'> 1 1 I believe this means that we can't unilaterally switch to A |
@AA-Turner I think one simply needs a branching logic in sphinx/sphinx/ext/autodoc/preserve_defaults.py Lines 168 to 171 in 6183b6a
something like: KEYWORD_ONLY = Parameter.KEYWORD_ONLY
POSITIONAL_ONLY = Parameter.POSITIONAL_ONLY
POSITIONAL_OR_KEYWORD = Parameter.POSITIONAL_OR_KEYWORD
VAR_KEYWORD = Parameter.VAR_KEYWORD
VAR_POSITIONAL = Parameter.VAR_POSITIONAL
def has_po_args(func: Callable, /) -> bool:
sig = inspect.signature(func)
return POSITIONAL_ONLY in {p.kind for p in sig.parameters.values()}
[...]
if bound_method and inspect.ismethod(obj):
# classmethods
kind = POSITIONAL_ONLY if has_po_args(obj) else POSITIONAL_OR_KEYWORD
cls = inspect.Parameter('cls', kind)
parameters.insert(0, cls) Talking about tortured cases, there is one edge-case not covered by this approach: class Lobster:
@classmethod
def spam(cls, /, ham, *, eggs: int) -> None: # note: no '/'
print(cls, ham, eggs) I think this is solved by inspecting def has_po_args(func: Callable, /) -> bool:
if is_classmethod(func):
sig = inspect.signature(func.__func__)
else:
sig = inspect.signature(func)
return POSITIONAL_ONLY in {p.kind for p in sig.parameters.values()} Implementing |
Sphinx 7.2.3 has been released with a fix for the issue mentioned by @randolf-scholz. A |
Describe the bug
After the 7.1 release, the kornia docs started to show warnings for throw exceptions from autodocs for some dataclass. I think is some issue with autodoc for
dataclass
classes.How to Reproduce
I could not reduce it to something small and reproducible -- but all the warnings on kornia docs occurs on data classes
$ git clone git@github.com:kornia/kornia.git $ virtualvenv venv -p python3.10 $ pip install -e .[docs] $ make build-docs SPHINXOPTS="-W"
Environment Information
Sphinx extensions
Additional context
list complete the extensions:
[
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
'sphinx_autodoc_defaultargs',
'sphinx_copybutton',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinxcontrib.bibtex',
"sphinxcontrib.gtagjs",
'sphinxcontrib.youtube',
'sphinx_design',
]
this issue can also be checked on the kornia CI -- https://github.com/kornia/kornia/actions/workflows/docs.yml
The text was updated successfully, but these errors were encountered: