Skip to content

gh-111420: Allow type comments in parenthesized with statements #111468

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

Merged
merged 4 commits into from
Oct 31, 2023

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Oct 29, 2023

I ran make regen-pegen and make regen-ast, I hope that's all that is needed :)

I also wanted to add some regression tests, but I I'm not sure where to put them. Should they go in test_ast.py or somewhere else? This is what I have in mind:

tree = ast.parse("with (a as b): # type: foo\n    pass", type_comments=True)
self.assertEqual("""\
Module(
    body=[
        With(
            items=[
                withitem(
                    context_expr=Name(id='a', ctx=Load()),
                    optional_vars=Name(id='b', ctx=Store()))],
            body=[
                Pass()],
            type_comment='foo')],
    type_ignores=[])""", ast.dump(tree, indent=4))
        
tree = ast.parse("with (a, b): # type: foo\n    pass", type_comments=True)
self.assertEqual("""\
Module(
    body=[
        With(
            items=[
                withitem(
                    context_expr=Name(id='a', ctx=Load())),
                withitem(
                    context_expr=Name(id='b', ctx=Load()))],
            body=[
                Pass()],
            type_comment='foo')],
    type_ignores=[])""", ast.dump(tree, indent=4))

@pablogsal
Copy link
Member

This is missing a test in test_type_comments.py:

https://github.com/python/cpython/blob/main/Lib/test/test_type_comments.py

@tomasr8
Copy link
Member Author

tomasr8 commented Oct 31, 2023

Thanks for letting me know! I'll add it

Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pablogsal pablogsal enabled auto-merge (squash) October 31, 2023 20:32
@tomasr8
Copy link
Member Author

tomasr8 commented Oct 31, 2023

LGTM

Damn you're fast 👀 😄

@pablogsal pablogsal merged commit 453e96e into python:main Oct 31, 2023
@tomasr8 tomasr8 deleted the with-type-comment branch October 31, 2023 21:10
FullteaR pushed a commit to FullteaR/cpython that referenced this pull request Nov 3, 2023
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants