This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2019-01-01 18:02 by thautwarm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
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 Taskaya (BTaskaya) * (Python committer) 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.
msg363372 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-03-04 18:25
I just removed Suite node in GH-18513, so I guess this can be closed.
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79813
2020-03-04 18:25:34BTaskayasetstatus: open -> closed
resolution: not a bug
messages: + msg363372

stage: resolved
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