5

I have some functions like

f(x, propagation_speed=scipy.constants.c)

I run sphinx-apidoc to generate documentation on them and them make html to get final HTML data.

Alas, Sphinx expands the constants and gives me something like

f(x, propagation_speed=299792458.0)

Cannot I somehow disable the default values expansion in docstrings? Could I add something to conf.py?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Felix
  • 3,351
  • 6
  • 40
  • 68
  • I don't believe it's expanding the values, it's retrieving the [function's signature](http://sphinx-doc.org/domains.html#signatures) python creates at function definition time [as you can do yourself](http://stackoverflow.com/questions/2677185/how-can-i-read-a-functions-signature). This is all Sphinx can see to get the data for the function signature shown on the documentation. – Poik Mar 25 '15 at 14:21
  • 3
    This also has been [asked before](http://stackoverflow.com/questions/21287477/can-i-suppress-variable-expansion-in-sphinx-documentation) but no one figured out an acceptable answer to it then, so I'm sure they'll be interested in any answers you find. – Poik Mar 25 '15 at 14:26

1 Answers1

0

A (dirty) fix. In your conf.py file add:

import re

def remove_default_value(app, what, name, obj, options, signature, return_annotation):
    if signature:
        search = re.findall(r"(\w*)=", signature)
        if search:
            signature = "({})".format(", ".join([s for s in search]))

    return (signature, return_annotation)

def setup(app):
    app.connect("autodoc-process-signature", remove_default_value)
felipe
  • 7,324
  • 2
  • 28
  • 37