-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Python synopsis and parameter cross-reference support #80
Conversation
This was missed in the refactoring that added the format_object_description_tooltip function.
I'm getting a conflict about confusion between a c'tor parameter that has the same name as a class attribute. .. autoclass:: RF24Mesh
:param int node_id: blah blah blah
.. autoattribute:: RF24Mesh.node_id simplified py src class RF24Mesh:
def __init__(self, node_id: int):
self._node_id = node_id # set node_id attribute
@property
def node_id(self) -> int:
return self._node_id Error output in build log is
This also seems to cause some confusion about which member to use when generating the synopsis in this instance. I noticed the synopsis for the parameter uses the attribute's docstring, but all links to attribute lead to the class c'tor param (probably because it is first in the toc). I also got a warning related to using
py src code: """circuitpython_nrf24l01.network.structs.py"""
def is_address_valid(address) -> bool:
# do logic
return address or False documented as .. automethod:: circuitpython_nrf24l01.network.structs.is_address_valid
Docstr for function.
:param address: blah blah blah Using On a positive note, these changes have alerted me about documented param names that are inconsistent with the actual param names in the signature 👍🏼 .. py:function:: some_func(param_name)
:param incorrect_param_name: blah blah blah This is mostly because I keep the majority of my docstrings - though not entire doctrings - in rst files (separate from py src code files) to save on storage space in microcontrollers. |
e066428
to
a50e000
Compare
This is a good point --- I'm not sure what the best solution is here. Currently I am assigning parameters the full name: Personally I think it is better to document constructors as separate
I'm a bit confused --- that looks like a function, not a method. Is the error happening when using Still it is kind of odd that it would make a difference --- seems like autodoc or the Python domain may be treating the first parameter (i.e. the "self" parameter) specially. Can you reproduce the issue using the plain Python domain, rather than autodoc? Note that autodoc works similarly to Breathe in that it ultimately just generates Python domain directives.
You might consider using some sort of preprocessing step to strip docstrings --- not sure if there is already something to do that. |
Not without intentionally omitting the arg from the signature. I probably shouldn't have mentioned it because it is not really a problem with these changes. Rather, it is a problem with improperly using autodoc. I only made note of it because it was but 1 of the obstacles I was working through in testing.
I don't know what to suggest here either. Would there be a way to conditionally inject So many people use autodoc that it would be a nuisance to require them to avoid using |
a50e000
to
f06059f
Compare
Your suggestion of adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. This is working flawlessly now. Thanks!
wait! now I can't get object_description_options = [
("py:.*", dict(generate_synopses=None)),
("py:parameter", dict(generate_synopses=None)),
] EDIT: I flushed the docs/_build and re-built from scratch. Now the synopses are disabled as desired. |
I'm also noticing that type hinting doesn't show if the signature doesn't have the type hints. This concerns me because I can't use proper type hinting in py src code's signatures on the platform I'm supporting (CircuitPython has no For Example: def func(arg1, arg2: int) -> None:
"""
:param bool arg1: blah blah blah
:param int arg2: blah blah blah
"""
return None Renders only the type hints given to the signature (not the type hints given to the |
This is now fixed --- if a parameter type is specified in the body, then it won't be overridden by the signature. |
f06059f
to
506c988
Compare
This adds a new `py:param` Sphinx role that can be used (in addition to the `py:obj` role) to reference parameters.
506c988
to
23a1697
Compare
23a1697
to
b992486
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find anything else that sticks out. Thanks again!
Note: This still requires some work --- this does not preserve parameter types specified outside of the signature, and does not gracefully handle invalid Python syntax as signatures, e.g. using brackets to indicate optional parameters.