Fix get_matrix() aliasing border rows when border > 1#429
Open
gaoflow wants to merge 1 commit into
Open
Conversation
`[[False] * width] * self.border` creates *border* references to the
same inner list object. When border > 1 this means all top (or all
bottom) border rows in the returned matrix share a single backing list,
so mutating any one of them silently corrupts the rest.
Replace the list-multiplication with list comprehensions to give every
border row its own independent list.
Reproducer (raises AssertionError before this fix):
qr = QRCode(border=4)
qr.add_data("1")
m = qr.get_matrix()
assert m[0] is not m[1] # was the *same* list – False without fix
Adds a regression test that verifies row identity and all-False content
for each border row when border=4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
[[False] * width] * self.bordercreates border references to the same inner list object. Whenborder > 1, all top border rows (and all bottom border rows) in the returned matrix share a single backing list, so mutating any one of them silently corrupts the rest.Reproducer
Fix
Replace the list-multiplication with list comprehensions so that every border row has its own independent list:
Tests
Added
test_get_matrix_border_rows_not_aliasedwhich verifies that, withborder=4, every pair of top/bottom border rows is a distinct object and all values areFalse.All 33 tests pass.