Uh oh!
There was an error while loading. Please reload this page.
[v3-3-test] Enable ruff B023 (function-uses-loop-variable) and fix violations (#70640) - #72273
Merged
Conversation
…olations (#70640) B023 catches the late-binding closure-over-loop-variable footgun where a function defined inside a loop captures the loop variable by reference, so every function in the resulting list sees the same (final) value — a classic silent-bug source in Python (https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result). The one user-visible fix is in providers/standard/.../triggers/file.py, where the FileTrigger's os.walk lambda was dispatched to a worker thread via anyio.to_thread.run_sync while the outer glob iteration could advance, potentially walking the wrong path. The rest are pre-existing latent-bug or false-positive sites in a migration script, breeze translation helpers, sphinx extensions, a system-test example DAG, the SMTP OAuth2 auth callback, secrets_masker subclass compat shim, and two provider unit tests — fixed by binding the loop-derived variable as a default argument on the inner function or lambda. (cherry picked from commit af0a377) Co-authored-by: Deepak kumar <deepakkumar@meta.com> Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
1 task
potiuk
marked this pull request as ready for review
August 29, 2026 23:48
potiuk
requested review from
amoghrajesh, ashb, bugraoz93, choo121600, ephraimbuddy, gopidesupavan, hussein-awala, jason810496, jedcunningham, jscheffl, potiuk, shahar1 and vatsrahul1001
as code ownersAugust 29, 2026 23:48
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
B023 catches the late-binding closure-over-loop-variable footgun where
a function defined inside a loop captures the loop variable by
reference, so every function in the resulting list sees the same
(final) value — a classic silent-bug source in Python
(https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result).
The one user-visible fix is in providers/standard/.../triggers/file.py,
where the FileTrigger's os.walk lambda was dispatched to a worker
thread via anyio.to_thread.run_sync while the outer glob iteration
could advance, potentially walking the wrong path.
The rest are pre-existing latent-bug or false-positive sites in a
migration script, breeze translation helpers, sphinx extensions, a
system-test example DAG, the SMTP OAuth2 auth callback, secrets_masker
subclass compat shim, and two provider unit tests — fixed by binding
the loop-derived variable as a default argument on the inner function
or lambda.
(cherry picked from commit af0a377)
Co-authored-by: Deepak kumar deepakkumar@meta.com
Co-authored-by: Jarek Potiuk jarek@potiuk.com