mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Add a Todo-type branch for type[P]
where P
is a protocol class (#19947)
This commit is contained in:
parent
24f6d2dc13
commit
e6dcdd29f2
5 changed files with 87 additions and 16 deletions
|
@ -849,6 +849,18 @@ impl<'db> Type<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn into_dynamic(self) -> Option<DynamicType> {
|
||||
match self {
|
||||
Type::Dynamic(dynamic_type) => Some(dynamic_type),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn expect_dynamic(self) -> DynamicType {
|
||||
self.into_dynamic()
|
||||
.expect("Expected a Type::Dynamic variant")
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn expect_class_literal(self) -> ClassLiteral<'db> {
|
||||
self.into_class_literal()
|
||||
|
|
|
@ -10198,6 +10198,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
|||
Type::ClassLiteral(class_literal) => {
|
||||
if class_literal.is_known(self.db(), KnownClass::Any) {
|
||||
SubclassOfType::subclass_of_any()
|
||||
} else if class_literal.is_protocol(self.db()) {
|
||||
SubclassOfType::from(
|
||||
self.db(),
|
||||
todo_type!("type[T] for protocols").expect_dynamic(),
|
||||
)
|
||||
} else {
|
||||
SubclassOfType::from(
|
||||
self.db(),
|
||||
|
|
|
@ -285,6 +285,12 @@ impl<'db> From<ClassType<'db>> for SubclassOfInner<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<DynamicType> for SubclassOfInner<'_> {
|
||||
fn from(value: DynamicType) -> Self {
|
||||
SubclassOfInner::Dynamic(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> From<SubclassOfInner<'db>> for Type<'db> {
|
||||
fn from(value: SubclassOfInner<'db>) -> Self {
|
||||
match value {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue