[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

## Summary

See https://github.com/astral-sh/ruff/pull/20338#discussion_r2337731998

## Test Plan

Regression test.
This commit is contained in:
David Peter 2025-09-11 10:14:38 +02:00 committed by GitHub
parent c6b92b918e
commit 59c8fda3f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -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
``` ```

View file

@ -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()
} }