Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ast.main is not covered #101821

Closed
sobolevn opened this issue Feb 11, 2023 · 0 comments
Closed

ast.main is not covered #101821

sobolevn opened this issue Feb 11, 2023 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Feb 11, 2023

All this code is not covered:

cpython/Lib/ast.py

Lines 1712 to 1737 in b652d40

def main():
import argparse
parser = argparse.ArgumentParser(prog='python -m ast')
parser.add_argument('infile', type=argparse.FileType(mode='rb'), nargs='?',
default='-',
help='the file to parse; defaults to stdin')
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=args.no_type_comments)
print(dump(tree, include_attributes=args.include_attributes, indent=args.indent))
if __name__ == '__main__':
main()

Proof: https://github.com/python/cpython/blob/b652d40f1c88fcd8595cd401513f6b7f8e499471/Lib/test/test_ast.py

If I remove def main, tests still pass.

So, my proposal is: add a simple test case that ensures that ast.main is there. I don't think that we need any fancy stuff. ast.main is only a thin wrapper around ast.parse and ast.dump which are fully tested on their own.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Feb 11, 2023
@sobolevn sobolevn self-assigned this Feb 11, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 11, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 12, 2023
iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Mar 12, 2023
warsaw pushed a commit to warsaw/cpython that referenced this issue Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants