8000 Fixed a bug that resulted in a false negative when evaluating binary … · codean-io/scip-python@170bfa0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 170bfa0

Browse files
committed
Fixed a bug that resulted in a false negative when evaluating binary operations that involve unions for either the LHS or RHS or both.
1 parent 60e1818 commit 170bfa0

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

packages/pyright-internal/src/analyzer/typeUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export function mapSubtypes(type: Type, callback: (type: Type) => Type | undefin
467467

468468
// Sorts types into a deterministic order.
469469
export function sortTypes(types: Type[]): Type[] {
470-
return types.sort((a, b) => {
470+
return types.slice(0).sort((a, b) => {
471471
if (a.category !== b.category) {
472472
return a.category - b.category;
473473
}

packages/pyright-internal/src/tests/samples/typeGuard3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def is_list(val: object) -> StrictTypeGuard[list[Any]]:
3434

3535
def func3(val: dict[str, str] | list[str] | list[int] | Sequence[int]):
3636
if is_list(val):
37-
reveal_type(val, expected_text="list[Any] | list[str] | list[int]")
37+
reveal_type(val, expected_text="list[str] | list[int] | list[Any]")
3838
else:
39-
reveal_type(val, expected_text="Sequence[int] | dict[str, str]")
39+
reveal_type(val, expected_text="dict[str, str] | Sequence[int]")
4040

4141

4242
def func4(val: dict[str, str] | list[str] | list[int] | tuple[int]):

packages/pyright-internal/src/tests/samples/typeNarrowingTypeIs1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def func4(a: Union[str, A]):
4646
if type(a) is B:
4747
reveal_type(a, expected_text="B")
4848
else:
49-
reveal_type(a, expected_text="A | str")
49+
reveal_type(a, expected_text="str | A")
5050

5151

5252
T = TypeVar("T")

0 commit comments

Comments
 (0)
0