[ty] Ensure annotation/type expressions in stub files are always deferred (#21401)

This commit is contained in:
Alex Waygood
2025-11-13 17:14:54 +00:00
committed by GitHub
parent 99694b6e4a
commit 90b32f3b3b
8 changed files with 115 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ def _(x: int | str | bytes | memoryview | range):
if isinstance(x, int | str):
reveal_type(x) # revealed: int | str
elif isinstance(x, bytes | memoryview):
reveal_type(x) # revealed: bytes | memoryview[Unknown]
reveal_type(x) # revealed: bytes | memoryview[int]
else:
reveal_type(x) # revealed: range
```
@@ -242,11 +242,11 @@ def _(flag: bool):
def _(flag: bool):
x = 1 if flag else "a"
# error: [invalid-argument-type] "Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Unknown, ...]`, found `Literal["a"]"
# error: [invalid-argument-type] "Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `Literal["a"]"
if isinstance(x, "a"):
reveal_type(x) # revealed: Literal[1, "a"]
# error: [invalid-argument-type] "Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Unknown, ...]`, found `Literal["int"]"
# error: [invalid-argument-type] "Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `Literal["int"]"
if isinstance(x, "int"):
reveal_type(x) # revealed: Literal[1, "a"]
```

View File

@@ -283,7 +283,7 @@ def flag() -> bool:
t = int if flag() else str
# error: [invalid-argument-type] "Argument to function `issubclass` is incorrect: Expected `type | UnionType | tuple[Unknown, ...]`, found `Literal["str"]"
# error: [invalid-argument-type] "Argument to function `issubclass` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `Literal["str"]"
if issubclass(t, "str"):
reveal_type(t) # revealed: <class 'int'> | <class 'str'>