[ty] callable type of a type object is not function-like (#22226)

This commit is contained in:
Carl Meyer
2025-12-28 11:24:45 -08:00
committed by GitHub
parent d5c39d3f9f
commit 4c4e652b38
2 changed files with 33 additions and 2 deletions

View File

@@ -290,4 +290,35 @@ C.f2(1)
C().f2(1)
```
## Types are not bound-method descriptors
```toml
[environment]
python-version = "3.14"
```
The callable type of a type object is not function-like.
```py
from typing import ClassVar
from ty_extensions import CallableTypeOf
class WithNew:
def __new__(self, x: int) -> WithNew:
return super().__new__(WithNew)
class WithInit:
def __init__(self, x: int) -> None:
pass
class C:
with_new: ClassVar[CallableTypeOf[WithNew]]
with_init: ClassVar[CallableTypeOf[WithInit]]
C.with_new(1)
C().with_new(1)
C.with_init(1)
C().with_init(1)
```
[`tensorbase`]: https://github.com/pytorch/pytorch/blob/f3913ea641d871f04fa2b6588a77f63efeeb9f10/torch/_tensor.py#L1084-L1092

View File

@@ -1222,7 +1222,7 @@ impl<'db> ClassType<'db> {
let dunder_new_bound_method = CallableType::new(
db,
dunder_new_signature.bind_self(db, Some(instance_ty)),
CallableTypeKind::FunctionLike,
CallableTypeKind::Regular,
);
if returns_non_subclass {
@@ -1292,7 +1292,7 @@ impl<'db> ClassType<'db> {
Some(CallableType::new(
db,
synthesized_dunder_init_signature,
CallableTypeKind::FunctionLike,
CallableTypeKind::Regular,
))
} else {
None