mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
[ty] Fix CallableTypeOf[…] for classmethods (#20345)
Some checks are pending
CI / cargo build (release) (push) Waiting to run
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 (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 / mkdocs (push) Waiting to run
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 / 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 / cargo build (release) (push) Waiting to run
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 (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 / mkdocs (push) Waiting to run
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 / 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 See https://github.com/astral-sh/ruff/pull/20338#discussion_r2337731998 ## Test Plan Regression test.
This commit is contained in:
parent
c6b92b918e
commit
59c8fda3f8
2 changed files with 7 additions and 1 deletions
|
@ -481,6 +481,10 @@ class Foo:
|
||||||
def returns_self(self, x: int) -> Self:
|
def returns_self(self, x: int) -> Self:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def class_method(cls, x: int) -> Self:
|
||||||
|
return cls(x)
|
||||||
|
|
||||||
def _(
|
def _(
|
||||||
c1: CallableTypeOf[f1],
|
c1: CallableTypeOf[f1],
|
||||||
c2: CallableTypeOf[f2],
|
c2: CallableTypeOf[f2],
|
||||||
|
@ -488,6 +492,7 @@ def _(
|
||||||
c4: CallableTypeOf[Foo],
|
c4: CallableTypeOf[Foo],
|
||||||
c5: CallableTypeOf[Foo(42).__call__],
|
c5: CallableTypeOf[Foo(42).__call__],
|
||||||
c6: CallableTypeOf[Foo(42).returns_self],
|
c6: CallableTypeOf[Foo(42).returns_self],
|
||||||
|
c7: CallableTypeOf[Foo.class_method],
|
||||||
) -> None:
|
) -> None:
|
||||||
reveal_type(c1) # revealed: () -> Unknown
|
reveal_type(c1) # revealed: () -> Unknown
|
||||||
reveal_type(c2) # revealed: () -> int
|
reveal_type(c2) # revealed: () -> int
|
||||||
|
@ -499,4 +504,5 @@ def _(
|
||||||
reveal_type(c5) # revealed: (x: int) -> str
|
reveal_type(c5) # revealed: (x: int) -> str
|
||||||
|
|
||||||
reveal_type(c6) # revealed: (x: int) -> Foo
|
reveal_type(c6) # revealed: (x: int) -> Foo
|
||||||
|
reveal_type(c7) # revealed: (x: int) -> Foo
|
||||||
```
|
```
|
||||||
|
|
|
@ -1166,7 +1166,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
||||||
if let Some(bound_method) = argument_type.into_bound_method() {
|
if let Some(bound_method) = argument_type.into_bound_method() {
|
||||||
binding
|
binding
|
||||||
.signature
|
.signature
|
||||||
.bind_self(self.db(), Some(bound_method.self_instance(db)))
|
.bind_self(self.db(), Some(bound_method.typing_self_type(db)))
|
||||||
} else {
|
} else {
|
||||||
binding.signature.clone()
|
binding.signature.clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue