Allow `set(True)` for boolean traps (#11287)

Closes https://github.com/astral-sh/ruff/issues/8923.
This commit is contained in:
Charlie Marsh 2024-05-04 17:33:08 -04:00 committed by GitHub
parent 1d20422ba9
commit c3e0306c9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -91,6 +91,12 @@ pub(super) fn allow_boolean_trap(call: &ast::ExprCall, checker: &Checker) -> boo
// boolean trap is allowed. We want to avoid raising a violation for cases in which the argument
// is positional-only and third-party, and this tends to be the case for setters.
if call.arguments.args.len() == 1 {
// Ex) `foo.set(True)`
if func_name == "set" {
return true;
}
// Ex) `foo.set_visible(True)`
if func_name
.strip_prefix("set")
.is_some_and(|suffix| suffix.starts_with(|c: char| c == '_' || c.is_ascii_uppercase()))