horast icon indicating copy to clipboard operation
horast copied to clipboard

docstring not parsed correctly

Open ZdenekM opened this issue 5 years ago • 2 comments

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.

ZdenekM avatar Apr 09 '20 05:04 ZdenekM

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

dferens avatar Jun 27 '20 15:06 dferens

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

ZdenekM avatar Sep 16 '20 06:09 ZdenekM