-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-45975: Simplify some while-loops with walrus operator #29347
Conversation
A code change this extensive must have a bpo issue where the advisability of this change can be debated. I intentionally did not click the [Approve and run] pending that. The opening 'comment' above can be copied as the opening post. It is far too long for a merge comment but great as an issue opener. Connect this PR to the issue by adding 'bpo-#####' to the title. Some issues: Backports: Code reformats are often not backported. In the other hand, I would want idlelib changes backported after reviewing them. Make a separate PR for idlelib changes. I will likely approve and merge it but have little opinion re other modules. Deprecated modules (distutils) are generally not patched. There might be other reasons to oppose changes other modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm other than 1 potential bug. The changes definitely need to be discussed on the bpo, but it's a +1 from me!
This PR is stale because it has been open for 30 days with no activity. |
You really need to:
The bpo is used since pre-Github times (Python repository migrated many times between hostings), so all development discussions go there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why parentheses are used? They are not required as I see.
This will make backports to 3.6 and 3.7 more complicated. |
@iritkatriel Are backports necessary here? This is neither a bugfix nor a new feature. |
No but if there will be a need in the future to backport a security fix in the same code, it won’t work cleanly because of this PR. So that’s an argument against this sweeping change. What is the argument in its favour? |
cbf91c6
to
062b0b0
Compare
Rebased on main. Reverted changes to distutils (deprecated) and idlelib (split off to #31083). |
For future PRs to CPython, please don’t use force pushes, they make poor experience for reviewers. |
I saw that aifc is among the "dead batteries" to be removed, so I undid the change there. |
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
🤖 New build scheduled with the buildbot fleet by @ethanfurman for commit 1583049 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Hello, just checking in on this. I suppose it needs to be updated. I can do that, or someone else can. |
@nickdrozd Can you resolve the merge conflicts? I will then review. |
@eendebakpt Updated! |
PR looks good to me. The status is awaiting merge. I guess @ethanfurman will have to do that. |
Thanks to all the reviewers! Your work is greatly appreciated ❤️ |
The following pattern occurs a few times in the codebase:
There is an unbounded
while
loop in which some kind of input is read. If the input is there, it is processed and the loop is continued; otherwise the loop is broken.This can be expressed more cleanly with the walrus operator:
Some of this code goes back to the days of Python 1. I assume that the original authors would have used the walrus idiom if it had been available, which it wasn't. But now it is.
Rewriting the instances of this pattern shaves off 148 lines from the codebase. Removing the manual
break
statements makes the logic more straightforward.This should not change the behavior of anything. I'm assuming that this code is all under test and that any deviations from the existing behavior will be caught. Anything that isn't tested shouldn't be changed (and should be tested).
https://bugs.python.org/issue45975