@@ -1586,21 +1586,22 @@ fn split_truthy_and_falsey_t(i_s: &InferenceState, t: &Type) -> Option<(Type, Ty
15861586 LiteralKind :: Int ( i) => check ( * i != 0 . into ( ) ) ,
15871587 _ => None ,
15881588 } ;
1589- let narrow_by_return_literal = |l : LookupDetails | {
1590- let inf = l. lookup . into_maybe_inferred ( ) ?;
1591- Some ( match inf. as_cow_type ( i_s) . maybe_callable ( i_s) ? {
1592- CallableLike :: Callable ( c) => match & c. return_type {
1593- Type :: Literal ( literal) => check_literal ( literal) ,
1594- _ => None ,
1595- } ,
1596- _ => None ,
1597- } )
1598- } ;
15991589
16001590 let check_class = |class : Class | {
16011591 let narrow_class_by_return_literal = |name| {
1602- let l = class. lookup ( i_s, name, ClassLookupOptions :: new ( & |_| false ) ) ;
1603- narrow_by_return_literal ( l)
1592+ let l = match t {
1593+ Type :: EnumMember ( e) => lookup_on_enum_instance ( i_s, & |_| false , & e. enum_ , name) ,
1594+ Type :: Enum ( e) => lookup_on_enum_instance ( i_s, & |_| false , e, name) ,
1595+ _ => class. lookup ( i_s, name, ClassLookupOptions :: new ( & |_| false ) ) ,
1596+ } ;
1597+ let inf = l. lookup . into_maybe_inferred ( ) ?;
1598+ Some ( match inf. as_cow_type ( i_s) . maybe_callable ( i_s) ? {
1599+ CallableLike :: Callable ( c) => match & c. return_type {
1600+ Type :: Literal ( literal) => check_literal ( literal) ,
1601+ _ => None ,
1602+ } ,
1603+ _ => None ,
1604+ } )
16041605 } ;
16051606
16061607 if let Some ( maybe_specific_bool) = narrow_class_by_return_literal ( "__bool__" ) {
@@ -1609,23 +1610,13 @@ fn split_truthy_and_falsey_t(i_s: &InferenceState, t: &Type) -> Option<(Type, Ty
16091610 check_literal ( & Literal :: new ( LiteralKind :: Int ( nt. params ( ) . len ( ) . into ( ) ) ) )
16101611 } else if let Some ( maybe_specific_len) = narrow_class_by_return_literal ( "__len__" ) {
16111612 maybe_specific_len
1612- } else if class . use_cached_class_infos ( i_s. db ) . is_final {
1613+ } else if t . is_final ( i_s. db ) {
16131614 Some ( ( t. clone ( ) , Type :: Never ( NeverCause :: Other ) ) )
16141615 } else {
16151616 None
16161617 }
16171618 } ;
16181619
1619- let check_enum = |enum_| {
1620- // By default bool(<Some Enum Member>) is True, but __bool__/__len__ can change that.
1621- let check_dunder = |name| {
1622- let l = lookup_on_enum_instance ( i_s, & |_| false , enum_, name) ;
1623- narrow_by_return_literal ( l)
1624- } ;
1625- check_dunder ( "__bool__" )
1626- . or_else ( || check_dunder ( "__len__" ) )
1627- . unwrap_or_else ( || Some ( ( t. clone ( ) , Type :: Never ( NeverCause :: Other ) ) ) )
1628- } ;
16291620 match t {
16301621 Type :: None => Some ( ( Type :: Never ( NeverCause :: Other ) , Type :: None ) ) ,
16311622 Type :: Literal ( literal) => check_literal ( literal) ,
@@ -1662,8 +1653,8 @@ fn split_truthy_and_falsey_t(i_s: &InferenceState, t: &Type) -> Option<(Type, Ty
16621653 }
16631654 } ) ,
16641655 Type :: Dataclass ( c) => check_class ( c. class ( i_s. db ) ) ,
1665- Type :: EnumMember ( member) => check_enum ( & member. enum_ ) ,
1666- Type :: Enum ( enum_) => check_enum ( enum_) ,
1656+ Type :: EnumMember ( member) => check_class ( member. enum_ . class ( i_s . db ) ) ,
1657+ Type :: Enum ( enum_) => check_class ( enum_. class ( i_s . db ) ) ,
16671658 Type :: TypedDict ( td) if td. has_required_members ( i_s. db ) => {
16681659 Some ( ( t. clone ( ) , Type :: NEVER ) )
16691660 }
0 commit comments