@@ -3173,7 +3173,10 @@ impl KnownClass {
31733173
31743174 /// Determine whether instances of this class are always truthy, always falsy,
31753175 /// or have an ambiguous truthiness.
3176- pub ( crate ) const fn bool ( self ) -> Truthiness {
3176+ ///
3177+ /// Returns `None` for `KnownClass::Tuple`, since the truthiness of a tuple
3178+ /// depends on its spec.
3179+ pub ( crate ) const fn bool ( self ) -> Option < Truthiness > {
31773180 match self {
31783181 // N.B. It's only generally safe to infer `Truthiness::AlwaysTrue` for a `KnownClass`
31793182 // variant if the class's `__bool__` method always returns the same thing *and* the
@@ -3199,9 +3202,9 @@ impl KnownClass {
31993202 | Self :: GeneratorType
32003203 | Self :: AsyncGeneratorType
32013204 | Self :: MethodWrapperType
3202- | Self :: CoroutineType => Truthiness :: AlwaysTrue ,
3205+ | Self :: CoroutineType => Some ( Truthiness :: AlwaysTrue ) ,
32033206
3204- Self :: NoneType => Truthiness :: AlwaysFalse ,
3207+ Self :: NoneType => Some ( Truthiness :: AlwaysFalse ) ,
32053208
32063209 Self :: Any
32073210 | Self :: BaseException
@@ -3218,7 +3221,6 @@ impl KnownClass {
32183221 | Self :: StdlibAlias
32193222 | Self :: SupportsIndex
32203223 | Self :: Set
3221- | Self :: Tuple
32223224 | Self :: Int
32233225 | Self :: Type
32243226 | Self :: Bytes
@@ -3257,7 +3259,9 @@ impl KnownClass {
32573259 | Self :: KwOnly
32583260 | Self :: InitVar
32593261 | Self :: NamedTupleFallback
3260- | Self :: TypedDictFallback => Truthiness :: Ambiguous ,
3262+ | Self :: TypedDictFallback => Some ( Truthiness :: Ambiguous ) ,
3263+
3264+ Self :: Tuple => None ,
32613265 }
32623266 }
32633267
@@ -4023,16 +4027,18 @@ impl KnownClass {
40234027 }
40244028 }
40254029
4026- /// Return true if all instances of this `KnownClass` compare equal.
4027- pub ( super ) const fn is_single_valued ( self ) -> bool {
4030+ /// Returns `Some(true)` if all instances of this `KnownClass` compare equal.
4031+ /// Returns `None` for `KnownClass::Tuple`, since whether or not a tuple type
4032+ /// is single-valued depends on the tuple spec.
4033+ pub ( super ) const fn is_single_valued ( self ) -> Option < bool > {
40284034 match self {
40294035 Self :: NoneType
40304036 | Self :: NoDefaultType
40314037 | Self :: VersionInfo
40324038 | Self :: EllipsisType
40334039 | Self :: TypeAliasType
40344040 | Self :: UnionType
4035- | Self :: NotImplementedType => true ,
4041+ | Self :: NotImplementedType => Some ( true ) ,
40364042
40374043 Self :: Any
40384044 | Self :: Bool
@@ -4045,7 +4051,6 @@ impl KnownClass {
40454051 | Self :: Complex
40464052 | Self :: Str
40474053 | Self :: List
4048- | Self :: Tuple
40494054 | Self :: Set
40504055 | Self :: FrozenSet
40514056 | Self :: Dict
@@ -4097,7 +4102,9 @@ impl KnownClass {
40974102 | Self :: Iterable
40984103 | Self :: Iterator
40994104 | Self :: NamedTupleFallback
4100- | Self :: TypedDictFallback => false ,
4105+ | Self :: TypedDictFallback => Some ( false ) ,
4106+
4107+ Self :: Tuple => None ,
41014108 }
41024109 }
41034110
0 commit comments