Repository navigation
Conversation
copy.copy of a PropertyBitmaps used Python's default shallow copy: the copy shared the original's dictionaries of labels and good counts, and its views, good, bad and bitmaps, were the original's objects, bound to it. A length added to the copy was added to the original too. __copy__ now makes a new PropertyBitmaps with the same property and copies of the two dictionaries, so its views read the copy. A length's labels are shared, as they are replaced when the length is labeled again, never changed. copy.deepcopy and pickle already kept the two apart. The new test fails on develop with copy.copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g and cost The docstring of __copy__ now says exactly what the copy owns, its dictionaries of lengths, while the labels inside them are shared, and that the copy is a PropertyBitmaps whatever the class of self. Its example also shows a view of the copy reading the copy. The tests now check that the bad view of a copy reads the copy too, that labeling a length kept as indices again, in the copy or in the original, changes only the one relabeled, which the sharing rests on, and that copying lengths kept as indices, in an array and in a list, sizes no bitmap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Adds
PropertyBitmaps.__copy__, inpermuta/bisc/bisc.py, so thatcopy.copyof aPropertyBitmapsgives one whose lengths are its own. Until now the copy shared the original's dictionaries, and its views,good,badandbitmaps, were the original's objects, so a length added to the copy was added to the original too:On
developthe last two lines give([3, 4], [3, 4])and(True, True).copy.deepcopyandpicklealready kept the two apart, and are unchanged.PropertyBitmapsis new in Unreleased (#209), so no release has the old behavior.Details
Why
copy.copyused Python's default shallow copy, which copies the instance's attributes as they are: the dictionaries of labels and of good counts, and the three views, each bound to the original. Copying aPropertyBitmapsto try a length or another property on it is a natural use, and it changed the original without a word.What changes
PropertyBitmaps.__copy__makes a newPropertyBitmapswith the same property and gives it copies of the two dictionaries, so its views read the copy.PropertyBitmaps, whatever the class ofself, as its docstring says. Nothing in Permuta, Tilings or comb_spec_searcher subclasses the class.tests/bisc/test_property_bitmaps.pygetstest_a_copy_keeps_its_lengths_apart_from_the_original, forcopy.copyandcopy.deepcopy, on lengths kept in both forms. It checks that:tests/bisc/test_sparse_storage.pygets two tests of what the copy shares:test_relabeling_a_length_kept_as_indices_changes_only_one: lengths kept as an array, labeled again in the copy or in the original, change only in the one relabeled. The sharing rests on that.test_a_copy_of_lengths_kept_as_indices_sizes_no_bitmap: a copy of lengths kept as indices, in an array and, past length 20, in a list, sizes no bitmap, where building one at length 14 would take 10.9 GB.CHANGELOG.mdentry, as Unreleased already namesPropertyBitmaps.Checks
tox: flake8, mypy, pylint and black pass. On CPython 3.15 all 702 tests pass, the doctests of
bisc.pyamong them. On PyPy 3.12, 700 pass and 2 are skipped, which need CPython's reference counting and tracemalloc.Against
develop: every new test fails, on both Pythons, but for thecopy.deepcopycase, whichdevelopalready got right.Downstream: Tilings' 3,722 tests pass at its
developwith this Permuta, on both Pythons.Faults made by hand, each run against the tests. Each of these fails at least one test:
develop's shallow copy;_keepoverwriting a kept array in place;dict(self.bitmaps).mutmut's six mutants of
__copy__are killed too.Speed:
copy.copytakes 0.93 µs againstdevelop's 0.98 under CPython, and 0.04 µs against 0.64 under PyPy. That is for aPropertyBitmapsofPerm.is_increasingwith lengths 0 to 8.copy.deepcopyandpickleare level.AI assistance: written with Claude Code (Opus 5.5) as the Permuta developer, and reviewed before submission by Claude Code (Opus 5.5) as an automated reviewer; Henning Ulfarsson checked and opened it.