Skip to content

Commit e1eacb1

Browse files
authored
[ty] More return type inference preparations (#29298)
A few more mdtest changes in preparation for return type inference.
1 parent e03746c commit e1eacb1

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎crates/ty_python_semantic/resources/mdtest/call/union.md‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ def _(factory: type[IntDiag] | type[StrDiag]):
202202
## Any non-callable variant
203203

204204
```py
205-
def f1(a: int): ...
205+
from typing import Any
206+
207+
def f1(a: int) -> Any: ...
206208
def _(flag: bool):
207209
if flag:
208210
f = f1
@@ -211,14 +213,16 @@ def _(flag: bool):
211213

212214
# error: [call-non-callable] "Object of type `Literal["This is a string literal"]` is not callable"
213215
x = f(3)
214-
reveal_type(x) # revealed: Unknown
216+
reveal_type(x) # revealed: Any
215217
```
216218

217219
## Union of binding errors
218220

219221
```py
220-
def f1(): ...
221-
def f2(): ...
222+
from typing import Any
223+
224+
def f1() -> Any: ...
225+
def f2() -> Any: ...
222226
def _(flag: bool):
223227
if flag:
224228
f = f1
@@ -228,15 +232,17 @@ def _(flag: bool):
228232
# error: [too-many-positional-arguments] "Too many positional arguments to function `f1`: expected 0, got 1"
229233
# error: [too-many-positional-arguments] "Too many positional arguments to function `f2`: expected 0, got 1"
230234
x = f(3)
231-
reveal_type(x) # revealed: Unknown
235+
reveal_type(x) # revealed: Any
232236
```
233237

234238
## One not-callable, one wrong argument
235239

236240
```py
241+
from typing import Any
242+
237243
class C: ...
238244

239-
def f1(): ...
245+
def f1() -> Any: ...
240246
def _(flag: bool):
241247
if flag:
242248
f = f1
@@ -246,7 +252,7 @@ def _(flag: bool):
246252
# error: [too-many-positional-arguments] "Too many positional arguments to function `f1`: expected 0, got 1"
247253
# error: [call-non-callable] "Object of type `C` is not callable"
248254
x = f(3)
249-
reveal_type(x) # revealed: Unknown
255+
reveal_type(x) # revealed: Any
250256
```
251257

252258
## Union including a special-cased function

‎crates/ty_python_semantic/resources/mdtest/function/return_type_inference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def returns_class():
316316
Inner1 = returns_class()
317317
Inner2 = returns_class()
318318

319-
# This should be `bool` or `Literal[False]`, not `Literal[True]`
319+
# TODO: This should be `bool` or `Literal[False]`, not `Literal[True]`
320320
reveal_type(Inner1 is Inner2) # revealed: bool
321321

322322
# TODO: This should ideally be an error

‎crates/ty_python_semantic/resources/mdtest/type_properties/truthiness.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class CustomLenEnum(Enum):
202202
NO = 0
203203
YES = 1
204204

205-
def __len__(self):
205+
def __len__(self) -> int:
206206
return 0
207207

208208
reveal_type(bool(NormalEnum.NO)) # revealed: Literal[True]

0 commit comments

Comments
 (0)