Fixed bug in narrowing logic for sequence pattern magic where special cases of str, bytes, and bytearray were not handled correctly. This addresses #6670. (#6671)

This commit is contained in:
Eric Traut 2023-12-06 22:03:22 -08:00 committed by GitHub
parent 0e71f1dbf9
commit 07568b047d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -1236,6 +1236,13 @@ function getSequencePatternInfo(
ClassType.isBuiltIn(mroClass, 'bytes') ||
ClassType.isBuiltIn(mroClass, 'bytearray')
) {
// This is definitely not a match.
sequenceInfo.push({
subtype,
entryTypes: [],
isIndeterminateLength: true,
isDefiniteNoMatch: true,
});
return;
}

View File

@ -427,3 +427,11 @@ def test_negative_narrowing6(a: str | None, b: str | None):
reveal_type(x, expected_text="tuple[None, str | None]")
case (a, b) as x:
reveal_type(x, expected_text="tuple[str | None, str | None]")
def test_negative_narrowing7(a: tuple[str, str] | str):
match a:
case (_, _):
reveal_type(a, expected_text="tuple[str, str]")
case _:
reveal_type(a, expected_text="str")