MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Lib/ast.py:641–691  ·  view source on GitHub ↗
(args=None)

Source from the content-addressed store, hash-verified

639
640
641def main(args=None):
642 import argparse
643 import sys
644
645 parser = argparse.ArgumentParser(color=True)
646 parser.add_argument('infile', nargs='?', default='-',
647 help='the file to parse; defaults to stdin')
648 parser.add_argument('-m', '--mode', default='exec',
649 choices=('exec', 'single', 'eval', 'func_type'),
650 help='specify what kind of code must be parsed')
651 parser.add_argument('--no-type-comments', default=True, action='store_false',
652 help="don't add information about type comments")
653 parser.add_argument('-a', '--include-attributes', action='store_true',
654 help='include attributes such as line numbers and '
655 'column offsets')
656 parser.add_argument('-i', '--indent', type=int, default=3,
657 help='indentation of nodes (number of spaces)')
658 parser.add_argument('--feature-version',
659 type=str, default=None, metavar='VERSION',
660 help='Python version in the format 3.x '
661 '(for example, 3.10)')
662 parser.add_argument('-O', '--optimize',
663 type=int, default=-1, metavar='LEVEL',
664 help='optimization level for parser (default -1)')
665 parser.add_argument('--show-empty', default=False, action='store_true',
666 help='show empty lists and fields in dump output')
667 args = parser.parse_args(args)
668
669 if args.infile == '-':
670 name = '<stdin>'
671 source = sys.stdin.buffer.read()
672 else:
673 name = args.infile
674 with open(args.infile, 'rb') as infile:
675 source = infile.read()
676
677 # Process feature_version
678 feature_version = None
679 if args.feature_version:
680 try:
681 major, minor = map(int, args.feature_version.split('.', 1))
682 except ValueError:
683 parser.error('Invalid format for --feature-version; '
684 'expected format 3.x (for example, 3.10)')
685
686 feature_version = (major, minor)
687
688 tree = parse(source, name, args.mode, type_comments=args.no_type_comments,
689 feature_version=feature_version, optimize=args.optimize)
690 print(dump(tree, include_attributes=args.include_attributes,
691 indent=args.indent, show_empty=args.show_empty))
692
693if __name__ == '__main__':
694 main()

Callers 1

ast.pyFile · 0.70

Calls 8

parse_argsMethod · 0.95
errorMethod · 0.95
openFunction · 0.70
parseFunction · 0.70
dumpFunction · 0.70
add_argumentMethod · 0.45
readMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…