Skip to content

Commit 272664e

Browse files
committed
ENH(sphinxext) convey also signature fromw rapped fn ...
as tipped in this comment: sphinx-doc/sphinx#3783 (comment)
1 parent 783b776 commit 272664e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

graphtik/sphinxext/__init__.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from sphinx.ext.autodoc import ModuleDocumenter
2626
from sphinx.locale import _, __
2727
from sphinx.roles import XRefRole
28+
from sphinx.util import inspect
2829
from sphinx.util import logging
2930
from sphinx.util.console import bold # pylint: disable=no-name-in-module
3031
from sphinx.writers.html import HTMLTranslator
@@ -515,14 +516,27 @@ def patched__can_document_member(cls, member, membername, isattr, parent):
515516
FuncDocClass.can_document_member = classmethod(patched__can_document_member)
516517

517518

518-
def setup(app: Sphinx):
519-
setup.app = app
520-
app.require_sphinx("2.0")
521-
app.setup_extension("sphinx.ext.doctest")
519+
def process_fnop_signature(app, what, name, obj, options, signature, return_annotation):
520+
try:
521+
if isinstance(obj, FnOp):
522+
fn = obj.fn
523+
fn_sig = inspect.signature(fn)
524+
signature = str(fn_sig)
525+
return_annotation = None
526+
except Exception as ex:
527+
log.error("Failed `autodoc-process-signature`: %s", ex, exc_info=1)
528+
return (signature, return_annotation)
529+
530+
531+
def _setup_autodoc(app: Sphinx):
522532
app.setup_extension("sphinx.ext.autodoc")
523533

524534
_teach_documenter_about_operations(app.registry.documenters["function"])
535+
app.connect("autodoc-process-signature", process_fnop_signature)
536+
525537

538+
def _setup_directive(app: Sphinx):
539+
app.setup_extension("sphinx.ext.doctest")
526540
app.add_config_value(
527541
"graphtik_graph_formats_by_builder",
528542
{"html": "svg", "readthedocs": "svg", "latex": "pdf"},
@@ -581,6 +595,14 @@ def setup(app: Sphinx):
581595
# Permanently set this, or else, e.g. +SKIP will not work!
582596
app.config.trim_doctest_flags = False
583597

598+
599+
def setup(app: Sphinx):
600+
setup.app = app
601+
app.require_sphinx("2.0")
602+
603+
_setup_autodoc(app)
604+
_setup_directive(app)
605+
584606
return {
585607
"version": __version__,
586608
"parallel_read_safe": True,

0 commit comments

Comments
 (0)