[flake8-simplify] Respect side effects in lambda defaults (SIM401) - #28000
Merged
Merged
Conversation
AlexWaygood
marked this pull request as draft
August 24, 2026 15:07
Member
Author
|
whoops, sorry, I haven't looked at this patch yet... |
Memory usage reportMemory usage unchanged ✅ |
|
| Project | Old Time | New Time | Change |
|---|---|---|---|
dd-trace-py |
3.08s | 0.72s | -77% |
Member
Author
|
Okay, I think this is good! |
AlexWaygood
marked this pull request as ready for review
August 24, 2026 15:16
|
ntBre
approved these changes
Aug 24, 2026
Contributor
There was a problem hiding this comment.
No mdtest? 😮 (just kidding, this is obviously fine)
1 task
1 task
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 free
to 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.
Summary
Fix
SIM401false positives when a lambda fallback has side-effectful parameter defaults:Replacing the conditional with
callback = callbacks.get(key, lambda value=initialize(): value)callsinitialize()even when the key exists. The conditional only calls it when the key is missing.any_over_exprnow visits lambda parameter defaults before the body. This extracts the helper change from #27634.The existing
SIM401snapshot fixture now covers positional-only, positional-or-keyword, and keyword-only defaults, including a nested call and a literal-default case that still gets a diagnostic.