[ty] Delegate truthiness inference of an enum Literal type to its enum-instance supertype (#21060)

This commit is contained in:
Alex Waygood 2025-10-24 14:34:16 +01:00 committed by GitHub
parent e196c2ab37
commit bf74c824eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 12 deletions

View file

@ -4692,10 +4692,10 @@ impl<'db> Type<'db> {
Truthiness::Ambiguous
}
Type::EnumLiteral(_) => {
// We currently make no attempt to infer the precise truthiness, but it's not impossible to do so.
// Note that custom `__bool__` or `__len__` methods on the class or superclasses affect the outcome.
Truthiness::Ambiguous
Type::EnumLiteral(enum_type) => {
enum_type
.enum_class_instance(db)
.try_bool_impl(db, allow_short_circuit, visitor)?
}
Type::IntLiteral(num) => Truthiness::from(*num != 0),