Skip to content

Commit

Permalink
Fix bug in SequenceValue / KnownValue interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Oct 18, 2023
1 parent fc3f543 commit a58fd45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions pyanalyze/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions pyanalyze/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a58fd45

Please sign in to comment.