Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,9 @@ impl<'db> Type<'db> {
| Type::DataclassDecorator(_)
| Type::DataclassTransformer(_)
| Type::ModuleLiteral(_)
| Type::PropertyInstance(_)
| Type::BoundSuper(_)
| Type::KnownInstance(_)
| Type::AlwaysTruthy => Truthiness::AlwaysTrue,

Type::AlwaysFalsy => Truthiness::AlwaysFalse,
Expand Down Expand Up @@ -3448,10 +3451,6 @@ impl<'db> Type<'db> {

Type::ProtocolInstance(_) => try_dunder_bool()?,

Type::KnownInstance(known_instance) => known_instance.bool(),

Type::PropertyInstance(_) => Truthiness::AlwaysTrue,

Type::Union(union) => try_union(*union)?,

Type::Intersection(_) => {
Expand All @@ -3464,7 +3463,6 @@ impl<'db> Type<'db> {
Type::StringLiteral(str) => Truthiness::from(!str.value(db).is_empty()),
Type::BytesLiteral(bytes) => Truthiness::from(!bytes.value(db).is_empty()),
Type::Tuple(items) => Truthiness::from(!items.elements(db).is_empty()),
Type::BoundSuper(_) => Truthiness::AlwaysTrue,
};

Ok(truthiness)
Expand Down
54 changes: 1 addition & 53 deletions crates/ty_python_semantic/src/types/known_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::fmt::Display;

use super::generics::GenericContext;
use super::{ClassType, Truthiness, Type, TypeAliasType, TypeVarInstance, class::KnownClass};
use super::{ClassType, Type, TypeAliasType, TypeVarInstance, class::KnownClass};
use crate::db::Db;
use crate::module_resolver::{KnownModule, file_to_module};
use ruff_db::files::File;
Expand Down Expand Up @@ -101,58 +101,6 @@ pub enum KnownInstanceType<'db> {
}

impl<'db> KnownInstanceType<'db> {
/// Evaluate the known instance in boolean context
pub(crate) const fn bool(self) -> Truthiness {
match self {
Self::Annotated
| Self::Literal
| Self::LiteralString
| Self::Optional
// This is a legacy `TypeVar` _outside_ of any generic class or function, so it's
// AlwaysTrue. The truthiness of a typevar inside of a generic class or function
// depends on its bounds and constraints; but that's represented by `Type::TypeVar` and
// handled in elsewhere.
| Self::TypeVar(_)
| Self::Union
| Self::NoReturn
| Self::Never
| Self::Tuple
| Self::Type
| Self::TypingSelf
| Self::Final
| Self::ClassVar
| Self::Callable
| Self::Concatenate
| Self::Unpack
| Self::Required
| Self::NotRequired
| Self::TypeAlias
| Self::TypeGuard
| Self::TypedDict
| Self::TypeIs
| Self::List
| Self::Dict
| Self::DefaultDict
| Self::Set
| Self::FrozenSet
| Self::Counter
| Self::Deque
| Self::ChainMap
| Self::OrderedDict
| Self::Protocol(_)
| Self::Generic(_)
| Self::ReadOnly
| Self::TypeAliasType(_)
| Self::Unknown
| Self::AlwaysTruthy
| Self::AlwaysFalsy
| Self::Not
| Self::Intersection
| Self::TypeOf
| Self::CallableTypeOf => Truthiness::AlwaysTrue,
}
}

pub(crate) fn normalized(self, db: &'db dyn Db) -> Self {
match self {
Self::Annotated
Expand Down
Loading