grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Pep 257: docstrings #127

Closed alanjds closed 5 years ago

alanjds commented 5 years ago

Docstrings are needed for some stdlib modules to be importable. E.g. struct.py imports __doc__ from _struct.py, but there the __doc__ is implicitly assumed as the 1st string statement of the file.

The actual PR assumes every module, class and function/method to start with an empty (None) __doc__. The AST visitor is told to take the 1st Str statement and inject an __doc__ = <value:str> "Assign" node.

It works very well for modules and module-level functions, but not for methods. Should be refactored later, maybe to show the __doc__ as a slot instead of a member of __dict__ of such function/method