-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Failed to create fix for UnnecessaryMap: Currently not supporting default values
#6715
Comments
The fix might not work if there are any falsy values in the iterable. For example, if one of the values of I do agree that the message isn't useful from user perspective and instead we should avoid auto-generating the fix. |
Yeah it's fine that this is unsupported, but we should attempting to fix it and thus raising the message. |
Can you expand on this with an example? |
Here, you can see the output is different. Default values in this context will never be used as In [1]: nums = [0, 1, 2]
In [2]: list(map(lambda x=1: x, nums))
Out[2]: [0, 1, 2]
In [3]: list(x if x else 1 for x in nums)
Out[3]: [1, 1, 2] |
But, isn't this suggesting that the user change |
Oh, it's mentioned in the PR description:
But yeah, your suggestion would work correctly. |
We should probably just skip attempting the fix if there are default values. It's an unusual pattern and I can think of a few cases where it would cause problems. |
Yeah, I'm thinking of the same solution. |
## Summary Avoid `C417` for `lambda` with default and variadic parameters. ## Test Plan `cargo test` and checking if it generates any autofix errors as test cases for `lambda` with default parameters already exists. fixes: #6715
Ruff 0.0.285
file content:
error:
For me, this error should not be visible for user, because this message is useless for it
PY_FILE_TEST_178904787.py.zip
The text was updated successfully, but these errors were encountered: