mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that results in incorrect type narrowing for a tuple with determinate length when indexed with an out-of-bounds slice. This addresses #7864. (#7901)
This commit is contained in:
parent
f7aba4ede4
commit
91dac9435e
@ -7577,16 +7577,16 @@ export function createTypeEvaluator(
|
||||
|
||||
if (value < 0) {
|
||||
value = tupleTypeArgs.length + value;
|
||||
if (value < 0) {
|
||||
return undefined;
|
||||
} else if (unboundedIndex >= 0 && value <= unboundedIndex) {
|
||||
if (unboundedIndex >= 0 && value <= unboundedIndex) {
|
||||
return undefined;
|
||||
} else if (value < 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (value > tupleTypeArgs.length) {
|
||||
return undefined;
|
||||
} else if (unboundedIndex >= 0 && value > unboundedIndex) {
|
||||
if (unboundedIndex >= 0 && value > unboundedIndex) {
|
||||
return undefined;
|
||||
} else if (value > tupleTypeArgs.length) {
|
||||
return tupleTypeArgs.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ def func1(val1: tuple[int, str, None], val2: tuple[int, ...]):
|
||||
reveal_type(x5, expected_text="tuple[int]")
|
||||
|
||||
x6 = val1[0:100]
|
||||
reveal_type(x6, expected_text="tuple[int | str | None, ...]")
|
||||
reveal_type(x6, expected_text="tuple[int, str, None]")
|
||||
|
||||
x7 = val2[:2]
|
||||
reveal_type(x7, expected_text="tuple[int, ...]")
|
||||
@ -83,3 +83,17 @@ def func3(val1: tuple[str, *Ts, None]):
|
||||
|
||||
x8 = val1[2:0]
|
||||
reveal_type(x8, expected_text="tuple[str | Union[*Ts@func3] | None, ...]")
|
||||
|
||||
|
||||
def func4(val1: tuple[str, int]):
|
||||
x1 = val1[2:]
|
||||
reveal_type(x1, expected_text="tuple[()]")
|
||||
|
||||
x2 = val1[-4:]
|
||||
reveal_type(x2, expected_text="tuple[str, int]")
|
||||
|
||||
x3 = val1[-4:-3]
|
||||
reveal_type(x3, expected_text="tuple[()]")
|
||||
|
||||
x4 = val1[:-3]
|
||||
reveal_type(x4, expected_text="tuple[()]")
|
||||
|
Loading…
Reference in New Issue
Block a user