diff --git a/crates/ty_python_semantic/resources/mdtest/subscript/class.md b/crates/ty_python_semantic/resources/mdtest/subscript/class.md index 86de205086..947f7fbbaf 100644 --- a/crates/ty_python_semantic/resources/mdtest/subscript/class.md +++ b/crates/ty_python_semantic/resources/mdtest/subscript/class.md @@ -19,6 +19,12 @@ class Identity: reveal_type(Identity[0]) # revealed: str ``` +`__class_getitem__` is implicitly a classmethod, so it can be called like this: + +```py +reveal_type(Identity.__class_getitem__(0)) # revealed: str +``` + ## Class getitem union ```py diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 6b3c2902c8..3730439017 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -725,7 +725,10 @@ impl<'db> FunctionType<'db> { /// classmethod. pub(crate) fn is_classmethod(self, db: &'db dyn Db) -> bool { self.has_known_decorator(db, FunctionDecorators::CLASSMETHOD) - || self.name(db) == "__init_subclass__" + || matches!( + self.name(db).as_str(), + "__init_subclass__" | "__class_getitem__" + ) } /// If the implementation of this function is deprecated, returns the `@warnings.deprecated`. diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 7259f9565d..7916fa1fc4 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -9203,7 +9203,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } - match ty.try_call(db, &CallArguments::positional([value_ty, slice_ty])) { + match ty.try_call(db, &CallArguments::positional([slice_ty])) { Ok(bindings) => return bindings.return_type(db), Err(CallError(_, bindings)) => { if let Some(builder) =