dadadel / pyment

Format and convert Python docstrings and generates patches
GNU General Public License v3.0
905 stars 62 forks source link

:rtype: is removed from doc comments; :return: loses indentation #9

Closed patkujawa-wf closed 7 years ago

patkujawa-wf commented 9 years ago

https://pythonhosted.org/an_example_pypi_project/sphinx.html#python-cross-referencing-syntax shows that :rtype: is the sphinx way to specify the type or return items, but pyment removes that tag from the docstring. It also seems to de-dent or lose the indentation of the :return: tag:

# Patch generated by Pyment v0.3.0

--- a/constants.py
# Patch generated by Pyment v0.3.0

--- a/constants.py
+++ b/constants.py
@@ -122,8 +124,8 @@

     :param range: A viewer structure range
     :type range: list or tuple
-    :return: A nice representation
-    :rtype: tuple
+:return: A nice representation
+
     """
     vs = VIEWER_STRUCTURE_KEYS
     _type = range[vs.RANGE_TYPE_IDX]
dadadel commented 9 years ago

Thanks @patkujawa-wf for reporting that issue. I will try to fix it ASAP.

dadadel commented 9 years ago

@patkujawa-wf a first way to address your problem is to write :returns: instead of :return: as returns is the expected syntax in reST format as you can notice in the link you provided. But the observed behaviour using your example is clearly buggy! And worth I noticed that inverting :rtype: line with :return: line will remove both lines!

patkujawa-wf commented 9 years ago

Thanks @dadadel! I wonder why PyCharm autocompletes on :return:? I've definitely see that in other docstrings, too, but good to know! :)

patkujawa-wf commented 9 years ago

@dadadel I'm confused, now, since http://sphinx-doc.org/domains.html#info-field-lists has an example that uses :return:, not :returns:. So which is correct?

.. py:function:: send_message(sender, recipient, message_body, [priority=1])

   Send a message to a recipient

   :param str sender: The person sending the message
   :param str recipient: The recipient of the message
   :param str message_body: The body of the message
   :param priority: The priority of the message, can be a number 1-5
   :type priority: integer or None
   :return: the message id
   :rtype: int
   :raises ValueError: if the message_body exceeds 160 characters
   :raises TypeError: if the message_body is not a basestring
maqifrnswa commented 7 years ago

Both are correct, return is an alias for returns: https://github.com/sphinx-doc/sphinx/blob/2ec179044bc7dfc647731a08bc3da7d6e133c994/sphinx/domains/c.py#L69 https://github.com/sphinx-doc/sphinx/blob/5f63aac209b0d23420ddb6374673ed13dd7ec4b2/doc/ext/napoleon.rst#L110

found this while running test suites, I'll take a look at it too

edit: added pull request #28

dadadel commented 7 years ago

@maqifrnswa Thanks for your fix. I updated your test commit.

dadadel commented 7 years ago

The issue is fixed by the PR #28.