How does one create a new logical argument type in function signatures?

10 views
Skip to first unread message

Vinay Sajip

unread,
Dec 2, 2019, 3:03:50 PM12/2/19
to sphinx-users
I have some Python documentation, the source of part of which looks like this:

.. class:: MyClass(stream, **kwargs)

   :param stream: The stream containing the text to be read.

   :param kwargs: Keyword arguments.

   :var bar: Bar

   :var baz: Baz

This renders to HTML like this:


ss1.png

I want to introduce a new category of parameter, whose source might be

   :myparam fizz: Fizz

   :myparam buzz: Buzz

which I want to render in a similar way:

ss2.png

I had thought to achieve this by adding an entry to the doc_field_types attribute of the PyObject class in the sphinx.domains.python module, but that doesn't seem to work. The original value of the list is

        PyTypedField('parameter', label=_('Parameters'),
                     names=('param', 'parameter', 'arg', 'argument',
                            'keyword', 'kwarg', 'kwparam'),
                     typerolename='class', typenames=('paramtype', 'type'),
                     can_collapse=True),
        PyTypedField('variable', label=_('Variables'), rolename='obj',
                     names=('var', 'ivar', 'cvar'),
                     typerolename='class', typenames=('vartype',),
                     can_collapse=True),
        PyGroupedField('exceptions', label=_('Raises'), rolename='exc',
                       names=('raises', 'raise', 'exception', 'except'),
                       can_collapse=True),
        Field('returnvalue', label=_('Returns'), has_arg=False,
              names=('returns', 'return')),
        PyField('returntype', label=_('Return type'), has_arg=False,
                names=('rtype',), bodyrolename='class'),

and I tried inserting a

        PyTypedField('myparam', label=_('My Parameters'),
                     names=('myarg_alias1', 'myarg_alias2'),
                     typerolename='class', typenames=('paramtype', 'type'),
                     can_collapse=True),

after the first entry (basically, like a parameter but with a different label and myparam keyword). However, the resulting HTML is like this:

ss3.png



What's the correct approach to obtain the result I want?

Regards,

Vinay Sajip

Reply all
Reply to author
Forward
0 new messages