mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
[ty] __class_getitem__
is a classmethod (#20192)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## 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
3 changed files with 11 additions and 2 deletions
|
@ -19,6 +19,12 @@ class Identity:
|
||||||
reveal_type(Identity[0]) # revealed: str
|
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
|
## Class getitem union
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|
|
@ -725,7 +725,10 @@ impl<'db> FunctionType<'db> {
|
||||||
/// classmethod.
|
/// classmethod.
|
||||||
pub(crate) fn is_classmethod(self, db: &'db dyn Db) -> bool {
|
pub(crate) fn is_classmethod(self, db: &'db dyn Db) -> bool {
|
||||||
self.has_known_decorator(db, FunctionDecorators::CLASSMETHOD)
|
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`.
|
/// 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),
|
Ok(bindings) => return bindings.return_type(db),
|
||||||
Err(CallError(_, bindings)) => {
|
Err(CallError(_, bindings)) => {
|
||||||
if let Some(builder) =
|
if let Some(builder) =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue