mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-17 11:17:17 +03:00
Fixed a bug in type narrowing for pattern matching in the negative (fall-through) case when the subject type contains an Any
. This addresses #5492. (#5499)
Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
parent
bb60966327
commit
6236155cb1
@ -61,6 +61,7 @@ import {
|
||||
import {
|
||||
addConditionToType,
|
||||
applySolvedTypeVars,
|
||||
containsAnyOrUnknown,
|
||||
convertToInstance,
|
||||
doForEachSubtype,
|
||||
getTypeCondition,
|
||||
@ -207,7 +208,7 @@ function narrowTypeBasedOnSequencePattern(
|
||||
}
|
||||
|
||||
let isPlausibleMatch = true;
|
||||
let isDefiniteMatch = true;
|
||||
let isDefiniteMatch = !containsAnyOrUnknown(type, /* recurse */ false);
|
||||
const narrowedEntryTypes: Type[] = [];
|
||||
let canNarrowTuple = entry.isTuple;
|
||||
|
||||
|
@ -32,6 +32,14 @@ def test_unknown(value_to_match):
|
||||
reveal_type(g1, expected_text="list[Unknown]")
|
||||
|
||||
|
||||
def test_any(value_to_match: Any):
|
||||
match value_to_match:
|
||||
case [*a1]:
|
||||
reveal_type(a1, expected_text="list[Any]")
|
||||
case b1:
|
||||
reveal_type(b1, expected_text="Any")
|
||||
|
||||
|
||||
def test_list(value_to_match: List[str]):
|
||||
match value_to_match:
|
||||
case a1, a2:
|
||||
|
Loading…
Reference in New Issue
Block a user