|
25 | 25 | from sphinx.ext.autodoc import ModuleDocumenter |
26 | 26 | from sphinx.locale import _, __ |
27 | 27 | from sphinx.roles import XRefRole |
| 28 | +from sphinx.util import inspect |
28 | 29 | from sphinx.util import logging |
29 | 30 | from sphinx.util.console import bold # pylint: disable=no-name-in-module |
30 | 31 | from sphinx.writers.html import HTMLTranslator |
@@ -515,14 +516,27 @@ def patched__can_document_member(cls, member, membername, isattr, parent): |
515 | 516 | FuncDocClass.can_document_member = classmethod(patched__can_document_member) |
516 | 517 |
|
517 | 518 |
|
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): |
522 | 532 | app.setup_extension("sphinx.ext.autodoc") |
523 | 533 |
|
524 | 534 | _teach_documenter_about_operations(app.registry.documenters["function"]) |
| 535 | + app.connect("autodoc-process-signature", process_fnop_signature) |
| 536 | + |
525 | 537 |
|
| 538 | +def _setup_directive(app: Sphinx): |
| 539 | + app.setup_extension("sphinx.ext.doctest") |
526 | 540 | app.add_config_value( |
527 | 541 | "graphtik_graph_formats_by_builder", |
528 | 542 | {"html": "svg", "readthedocs": "svg", "latex": "pdf"}, |
@@ -581,6 +595,14 @@ def setup(app: Sphinx): |
581 | 595 | # Permanently set this, or else, e.g. +SKIP will not work! |
582 | 596 | app.config.trim_doctest_flags = False |
583 | 597 |
|
| 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 | + |
584 | 606 | return { |
585 | 607 | "version": __version__, |
586 | 608 | "parallel_read_safe": True, |
|
0 commit comments