diff --git a/docs/changelog.md b/docs/changelog.md index 44bdd4bb..441efe69 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Fix bug in type compatibility check between known-length sequence + types and literal values (#701) + ## Version 0.11.0 (October 3, 2023) - Partial support for PEP 695-style type aliases. Scoping changes diff --git a/pyanalyze/test_value.py b/pyanalyze/test_value.py index a2e20d49..65693310 100644 --- a/pyanalyze/test_value.py +++ b/pyanalyze/test_value.py @@ -238,6 +238,10 @@ def test_sequence_value() -> None: ), ) + assert_can_assign(val, KnownValue((1, "x"))) + assert_cannot_assign(val, KnownValue((1, 2))) + assert_cannot_assign(val, KnownValue((1, "x", "y"))) + assert str(val) == "tuple[int, str]" assert str(value.SequenceValue(tuple, [(False, TypedValue(int))])) == "tuple[int]" assert ( diff --git a/pyanalyze/value.py b/pyanalyze/value.py index 6b6a484c..433e1a8c 100644 --- a/pyanalyze/value.py +++ b/pyanalyze/value.py @@ -1057,6 +1057,7 @@ def make_or_known( return SequenceValue(typ, members) def can_assign(self, other: Value, ctx: CanAssignContext) -> CanAssign: + other = replace_known_sequence_value(other) if isinstance(other, SequenceValue): can_assign = self.get_type_object(ctx).can_assign(self, other, ctx) if isinstance(can_assign, CanAssignError):