dadadel / pyment

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

__doc__ is not well parsed #90

Closed vallsv closed 3 years ago

vallsv commented 3 years ago

Hi.

Here is a buggy transformation using pygment test.py v0.3.3

It comes from a base code that i simplified to extract the problem. On the project the function is used as decorator to auto generate documentation.

Anyway the pygment result is not anymire valid.

Hope it can help.

def foo():
    __doc__ = """\
    Foo"""

Here is the patch result

--- a/test.py
+++ b/test.py
@@ -1,6 +1,6 @@

 def foo():
-    __doc__ = """\
-    Foo"""
+    """__doc__ = """\
+    Foo
dadadel commented 3 years ago

Hi! thanks for reporting. I think it is not related to __doc__. Actually, if there's something before triple quotes that are just after the function signature, the problem arises.

Thus, following docstrings will fail:

def foo():
    __doc__ = """\
    Foo"""

def bar(param):
    r"""this is a docstring
    """

def foobar():
    u"""this is a docstring
    """

def no_docs():
    something = '''bla bla bla'''

Producing the following patch:

# Patch generated by Pyment v0.3.3

--- a/issue90.py
+++ b/issue90.py
@@ -1,17 +1,17 @@
 def foo():
-    __doc__ = """\
-    Foo"""
+    """__doc__ = """\
+    Foo

 def bar(param):
-    r"""this is a docstring
-    """
+    """r"""this is a docstring
+
+    :param param:

 def foobar():
-    u"""this is a docstring
-    """
+    """u"""this is a docstring"""

 def no_docs():
-    something = '''bla bla bla'''
+    """something = '''bla bla bla"""
dadadel commented 3 years ago

@vallsv this is fixed in current master version. Can you check that your use case is addressed ?

vallsv commented 3 years ago

Thx