[red-knot] Minor simplifications and improvements to constraint narrowing logic (#15270)

This commit is contained in:
Alex Waygood
2025-01-05 21:51:22 +00:00
committed by GitHub
parent b26448926a
commit 980ce941c7
4 changed files with 52 additions and 45 deletions

View File

@@ -174,3 +174,11 @@ def _(flag: bool):
if isinstance(x, int, foo="bar"):
reveal_type(x) # revealed: Literal[1] | Literal["a"]
```
## `type[]` types are narrowed as well as class-literal types
```py
def _(x: object, y: type[int]):
if isinstance(x, y):
reveal_type(x) # revealed: int
```

View File

@@ -239,3 +239,11 @@ t = int if flag() else str
if issubclass(t, int, foo="bar"):
reveal_type(t) # revealed: Literal[int, str]
```
### `type[]` types are narrowed as well as class-literal types
```py
def _(x: type, y: type[int]):
if issubclass(x, y):
reveal_type(x) # revealed: type[int]
```