Skip to content

gh-122666: Tests for ast optimizations#122667

Merged
JelleZijlstra merged 24 commits into
python:mainfrom
Eclips4:tests_for_ast_opt
Aug 26, 2024
Merged

gh-122666: Tests for ast optimizations#122667
JelleZijlstra merged 24 commits into
python:mainfrom
Eclips4:tests_for_ast_opt

Conversation

@Eclips4

@Eclips4 Eclips4 commented Aug 4, 2024

Copy link
Copy Markdown
Member

@Eclips4

Eclips4 commented Aug 4, 2024

Copy link
Copy Markdown
Member Author

Hypothesis failure looks unrelated.

Comment thread Lib/test/test_ast/test_ast.py Outdated
Comment thread Lib/test/test_ast/test_ast.py Outdated
Comment thread Lib/test/test_ast/test_ast.py Outdated
Eclips4 and others added 2 commits August 5, 2024 07:32
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Comment thread Lib/test/test_ast/snippets.py Outdated
@Eclips4
Eclips4 requested a review from vstinner August 5, 2024 13:45
@Eclips4
Eclips4 marked this pull request as draft August 5, 2024 14:07

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I proposed to write "Lines below are generated by running (...)" into a separated file, not move eval_opt_tests into a separated file. Would it be possible?

@Eclips4
Eclips4 marked this pull request as ready for review August 8, 2024 18:44
print("]")
print("main()")
raise SystemExit
unittest.main()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This line is no longer needed since there's no unittest in snippets.py

Comment thread Lib/test/test_ast/test_ast.py
Comment thread Lib/test/test_ast/test_ast.py

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@JelleZijlstra: Do you want to review this change?

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are a few more optimizations this doesn't test. We could keep them for another PR if you want to, but they don't seem difficult to test:

  • not (a is b) -> a is not b
  • not (a in b) -> a not in b
  • (1,) * 3 -> (1, 1, 1)
  • It seems that in some cases it changes % formatting into f-strings but I haven't been able to trigger that
  • __debug__ gets turned into True or False

Comment thread Lib/test/test_ast/test_ast.py Outdated
Comment thread Lib/test/test_ast/test_ast.py Outdated
Comment thread Lib/test/test_ast/test_ast.py Outdated
Comment thread Lib/test/test_ast/test_ast.py Outdated
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@Eclips4

Eclips4 commented Aug 26, 2024

Copy link
Copy Markdown
Member Author

__debug__ gets turned into True or False

This is already tested by test_optimization_levels__debug__

@Eclips4
Eclips4 requested a review from JelleZijlstra August 26, 2024 19:01
@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) August 26, 2024 19:18
@Eclips4

Eclips4 commented Aug 26, 2024

Copy link
Copy Markdown
Member Author

@JelleZijlstra do you think it's worth backporting this to the 3.13 branch?
I think so, after reading #123344.

@JelleZijlstra

Copy link
Copy Markdown
Member

Yes, it's good to backport new tests in general so we can be more confident in bugfixes.

@JelleZijlstra JelleZijlstra added the needs backport to 3.13 bugs and security fixes label Aug 26, 2024
@JelleZijlstra
JelleZijlstra merged commit 9f9b00d into python:main Aug 26, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @Eclips4 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 26, 2024
(cherry picked from commit 9f9b00d)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-app

bedevere-app Bot commented Aug 26, 2024

Copy link
Copy Markdown

GH-123359 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 26, 2024
@Eclips4
Eclips4 deleted the tests_for_ast_opt branch August 26, 2024 19:28
@Eclips4

Eclips4 commented Aug 26, 2024

Copy link
Copy Markdown
Member Author

Yes, it's good to backport new tests in general so we can be more confident in bugfixes.

Oh, I forgot about 3.12 branch. I think it's also ok to backport it to 3.12. What do you think?

@JelleZijlstra

Copy link
Copy Markdown
Member

We can't because the optimize=1 argument didn't exist in 3.12. Maybe there's a way to make it work anyway, but not sure it's worth the effort.

@Eclips4

Eclips4 commented Aug 26, 2024

Copy link
Copy Markdown
Member Author

We can't because the optimize=1 argument didn't exist in 3.12. Maybe there's a way to make it work anyway, but not sure it's worth the effort.

Oh, yeah, you're right. I agree that it's not worth the effort.

JelleZijlstra added a commit that referenced this pull request Aug 27, 2024
(cherry picked from commit 9f9b00d)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants