Use truthiness check in auto_attribs detection (#14562)

This commit is contained in:
Charlie Marsh
2024-11-23 22:06:10 -05:00
committed by GitHub
parent d285717da8
commit de62e39eba
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,
}
}