Use truthiness check in auto_attribs detection (#14562)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

This commit is contained in:
Charlie Marsh 2024-11-23 22:06:10 -05:00 committed by GitHub
parent d285717da8
commit de62e39eba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 15 deletions

View file

@ -1118,6 +1118,8 @@ pub enum Truthiness {
Falsey,
/// The expression evaluates to a `True`-like value (e.g., `1`, `"foo"`).
Truthy,
/// The expression evaluates to `None`.
None,
/// The expression evaluates to an unknown value (e.g., a variable `x` of unknown type).
Unknown,
}
@ -1173,7 +1175,7 @@ impl Truthiness {
Self::False
}
}
Expr::NoneLiteral(_) => Self::Falsey,
Expr::NoneLiteral(_) => Self::None,
Expr::EllipsisLiteral(_) => Self::Truthy,
Expr::FString(f_string) => {
if is_empty_f_string(f_string) {
@ -1247,6 +1249,7 @@ impl Truthiness {
match self {
Self::True | Self::Truthy => Some(true),
Self::False | Self::Falsey => Some(false),
Self::None => Some(false),
Self::Unknown => None,
}
}