summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-12-16 18:23:27 (GMT)
committerVictor Stinner <vstinner@python.org>2019-12-16 18:23:27 (GMT)
commit814d687c7df3e0c60036943b68ece13f9f19dfef (patch)
treecec9acadee590122758df6220ae9b4c6139962dd /Lib/ast.py
parenta322f50c369e2e4138266c88e32ef83af95b2da6 (diff)
downloadcpython-814d687c7df3e0c60036943b68ece13f9f19dfef.zip
cpython-814d687c7df3e0c60036943b68ece13f9f19dfef.tar.gz
cpython-814d687c7df3e0c60036943b68ece13f9f19dfef.tar.bz2
bpo-38348: Extend command line options of ast parsing tool (GH-16540)
Add -i and --indent (indentation level), and --no-type-comments (type comments) command line options to ast parsing tool.
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 13ae9e0..ee3f743 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -1258,15 +1258,19 @@ def main():
parser.add_argument('-m', '--mode', default='exec',
choices=('exec', 'single', 'eval', 'func_type'),
help='specify what kind of code must be parsed')
+ parser.add_argument('--no-type-comments', default=True, action='store_false',
+ help="don't add information about type comments")
parser.add_argument('-a', '--include-attributes', action='store_true',
help='include attributes such as line numbers and '
'column offsets')
+ parser.add_argument('-i', '--indent', type=int, default=3,
+ help='indentation of nodes (number of spaces)')
args = parser.parse_args()
with args.infile as infile:
source = infile.read()
- tree = parse(source, args.infile.name, args.mode, type_comments=True)
- print(dump(tree, include_attributes=args.include_attributes, indent=3))
+ tree = parse(source, args.infile.name, args.mode, type_comments=args.no_type_comments)
+ print(dump(tree, include_attributes=args.include_attributes, indent=args.indent))
if __name__ == '__main__':
main()