classification
Title: support unparse for Suite ast
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, pablogsal, thautwarm
Priority: normal Keywords:

Created on 2019-01-01 18:02 by thautwarm, last changed 2019-12-01 18:50 by BTaskaya.

Messages (2)
msg332845 - (view) Author: thautwarm (thautwarm) * Date: 2019-01-01 18:02
Although `Suite` is not an actual AST used in CPython, it's quite useful when performing some code analysis. 

`Suite` is a sequence of statements which could be used to represent a block whose context inherits from outside block's.

Also, the document said it's useful in Jython.

I wonder if we could support `unparse` for Suite through making a tiny modification to

https://github.com/python/cpython/blob/master/Tools/parser/unparse.py

def _Suite(self, tree):
      for stmt in tree.body:
         self.dispatch(stmt)
msg357684 - (view) Author: Batuhan (BTaskaya) * Date: 2019-12-01 18:50
Tools/parser/unparse.py has been moved under ast module and exposed via ast.unparse() interface. If you want to support custom AST statements, the current version is incapable of doing such changes because of the real unparser class is private. As a workaround you can import it and subclass it /assign a method and then use ast.unparse() but that is a hacky way and there is no one who can guarantee if that unparser class will change its API or not. Currently it uses NodeVisitor API. Also you can use Berker's astor project to do this job, which gives you ability of changing source generator class.
History
Date User Action Args
2019-12-01 18:50:20BTaskayasetversions: + Python 3.9, - Python 3.6, Python 3.7, Python 3.8
nosy: + pablogsal, BTaskaya

messages: + msg357684

components: + Library (Lib), - Demos and Tools
2019-01-01 18:02:50thautwarmcreate