mirror of https://github.com/astral-sh/ruff
[ty] `__class_getitem__` is a classmethod (#20192)
## Summary `__class_getitem__` is [implicitly a classmethod](https://docs.python.org/3/reference/datamodel.html#object.__class_getitem__). ## Test Plan Added regression test.
This commit is contained in:
parent
5518c84ab3
commit
bbfcf6e111
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -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) =
|
||||
|
|
|
|||
Loading…
Reference in New Issue