Skip to content
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

docstring not parsed correctly #5

Open
ZdenekM opened this issue Apr 9, 2020 · 2 comments
Open

docstring not parsed correctly #5

ZdenekM opened this issue Apr 9, 2020 · 2 comments

Comments

@ZdenekM
Copy link

ZdenekM commented Apr 9, 2020

Following simple test fails:

import horast
import inspect

class Test:
    """
    multiline
    docstring
    """

original_code = inspect.getsource(Test)
tree = horast.parse(original_code)
unparsed_code = horast.unparse(tree)
assert original_code == unparsed_code

because tree looks like this:

Module(
  body=[ClassDef(
    name='Test',
    bases=[],
    keywords=[],
    body=[Expr(value=Str(
      s='\n    multiline\n    docstring\n    ',
      kind=''))],
    decorator_list=[])],
  type_ignores=[])

Would it be possible to fix this somehow? I can probably use some temporary workaround, but it would be really nice to have this working out of the box. I'm going to generate classes/methods with docstrings.

@dferens
Copy link

dferens commented Jun 27, 2020

Hi @ZdenekM ,
AST produced by horast is almost identical to one produced by ast, the problem is in different package - simonpercivall/astunparse#47
I suggest you to upgrade to 3.9: https://docs.python.org/3.9/library/ast.html#ast.unparse

@ZdenekM
Copy link
Author

ZdenekM commented Sep 16, 2020

@dferens Thanks for the tip, I will give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants