Skip to content

Commit 933e8d6

Browse files
committed
tests
1 parent e9ad519 commit 933e8d6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/ty_ide/src/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ quux.<CURSOR>
17911791
__init_subclass__ :: bound method type[Quux].__init_subclass__() -> None
17921792
__module__ :: str
17931793
__ne__ :: bound method Quux.__ne__(value: object, /) -> bool
1794-
__new__ :: bound method Quux.__new__() -> Quux
1794+
__new__ :: def __new__(cls) -> Self@__new__
17951795
__reduce__ :: bound method Quux.__reduce__() -> str | tuple[Any, ...]
17961796
__reduce_ex__ :: bound method Quux.__reduce_ex__(protocol: SupportsIndex, /) -> str | tuple[Any, ...]
17971797
__repr__ :: bound method Quux.__repr__() -> str

crates/ty_python_semantic/resources/mdtest/call/methods.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,27 @@ reveal_type(C.f2(1)) # revealed: str
588588
reveal_type(C().f2(1)) # revealed: str
589589
```
590590

591+
### `__new__`
592+
593+
`__new__` is an implicit `@staticmethod`; accessing it on an instance does not bind the `cls`
594+
argument:
595+
596+
```py
597+
from typing_extensions import Self
598+
599+
reveal_type(object.__new__) # revealed: def __new__(cls) -> Self@__new__
600+
reveal_type(object().__new__) # revealed: def __new__(cls) -> Self@__new__
601+
reveal_type(int.__new__) # revealed: Overload[(cls, x: @Todo(Support for `typing.TypeAlias`) = Literal[0], /) -> Self@__new__, (cls, x: str | bytes | bytearray, /, base: SupportsIndex) -> Self@__new__]
602+
reveal_type((42).__new__) # revealed: Overload[(cls, x: @Todo(Support for `typing.TypeAlias`) = Literal[0], /) -> Self@__new__, (cls, x: str | bytes | bytearray, /, base: SupportsIndex) -> Self@__new__]
603+
604+
class X:
605+
def __init__(self, val: int): ...
606+
607+
def make_another(self) -> Self:
608+
reveal_type(self.__new__) # revealed: def __new__(cls) -> Self@__new__
609+
return self.__new__(X)
610+
```
611+
591612
## Builtin functions and methods
592613

593614
Some builtin functions and methods are heavily special-cased by ty. This mdtest checks that various

0 commit comments

Comments
 (0)