mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-20 04:29:47 +00:00
[ty] Delegate truthiness inference of an enum Literal type to its enum-instance supertype (#21060)
This commit is contained in:
parent
e196c2ab37
commit
bf74c824eb
3 changed files with 37 additions and 12 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue