-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Autofix B006 (mutable-argument-default) #4693
Labels
fixes
Related to suggested fixes for violations
Comments
I'll give this one a go |
konstin
added a commit
that referenced
this issue
Aug 10, 2023
## Summary Reopening of #4880 One open TODO as described in: #4880 (comment) FYI @charliermarsh seeing as you commented you wanted to do final review and merge. @konstin @dhruvmanila @MichaReiser as previous reviewers. # Old Description ## Summary Adds an autofix for B006 turning mutable argument defaults into None and setting their original value back in the function body if still `None` at runtime like so: ```python def before(x=[]): pass def after(x=None): if x is None: x = [] pass ``` ## Test Plan Added an extra test case to existing fixture with more indentation. Checked results for all old examples. NOTE: Also adapted the jupyter notebook test as this checked for B006 as well. ## Issue link Closes: #4693 --------- Co-authored-by: konstin <[email protected]>
durumu
pushed a commit
to durumu/ruff
that referenced
this issue
Aug 12, 2023
## Summary Reopening of astral-sh#4880 One open TODO as described in: astral-sh#4880 (comment) FYI @charliermarsh seeing as you commented you wanted to do final review and merge. @konstin @dhruvmanila @MichaReiser as previous reviewers. # Old Description ## Summary Adds an autofix for B006 turning mutable argument defaults into None and setting their original value back in the function body if still `None` at runtime like so: ```python def before(x=[]): pass def after(x=None): if x is None: x = [] pass ``` ## Test Plan Added an extra test case to existing fixture with more indentation. Checked results for all old examples. NOTE: Also adapted the jupyter notebook test as this checked for B006 as well. ## Issue link Closes: astral-sh#4693 --------- Co-authored-by: konstin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
B006 could have an autofixer to instead make the default
None
and check if it isNone
within the function.pybetter includes a fixer for this:
This may want to also autofix the type hint to be
Optional
if there is one.The text was updated successfully, but these errors were encountered: