-
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
B008 complains about function call when constructing a default parameter value as a exception #8378
Comments
I'm definitely open-minded about improving the rule, but can you say a bit more about why you think this case should be excluded? Alternatively, why prefer this over the in-body initialization pattern? if error is None:
error = ValueError("Hosts weren't successfully added") |
In my case none is a valid meaningful parameter variant Creating sentinels as replacement is pretty painful |
Ahh I see, so passing in The challenge here is that I don't know how to avoid this without disabling the rule altogether. Even here, |
The rule is about function calls,I believe it's fair game to allow construction of built-in exceptions |
https://github.com/PyCQA/flake8-bugbear/blob/907e0dd29a99818591a604d4557c70ea33204712/bugbear.py#L1660-L1667 has more details in the error ruff/crates/ruff_linter/src/rules/flake8_bugbear/rules/function_call_in_argument_default.rs Line 60 in 4170ef0
i would recommend to extend the error with the suggestion |
Does that suggestion solve the problem for you though? Do you consider that a reasonable workaround? |
Yes |
https://play.ruff.rs/54edf8a4-4c2f-4c0e-a5d8-b7b4afa7a19e
a definition like
triggers
The text was updated successfully, but these errors were encountered: