Repository navigation
Conversation
This branch has not been deployed
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.
The change
Keep
copy.copy()ofLRIandLRUfrom sharing mutable cache bookkeeping with the source. In a two-entry cache, inserting into the shallow copy can currently make a source lookup return a value whose key is absent from that source's dictionary, or fail for a key that is still present.Reconstruct the shallow copy under the source lock, following the reduction factory, instance state and list/item iterators. When copied state shares cache internals with the source, rebuild an independent lock and linked-list bookkeeping while retaining dictionary and eviction order. Registered reducers, subclass hooks, factory-provided contents and non-cache factory results retain their reconstruction behavior. Independently constructed cache results keep their own internal state. Payload objects remain shared, as expected for a shallow copy. The explicit
cache.copy()method keeps its existing fresh-counter behavior; this does not add deepcopy or pickle support.On Windows / CPython 3.12.10, the full unit and doctest suite passes: 816 passed, 1 skipped, 22 subtests passed. The 75 cache tests cover source/copy independence, statistics, dictionary versus eviction order, shared mutable values, constructor arguments, slots, state hooks, reducer dispatch, filtered or transformed item iterators, list results, custom assignment hooks and factories returning existing cache objects. Twelve added reducer-output cases fail against the previous revision; all pass with this change.
git diff --checkalso passes. A separate Codex agent approved this exact revision after rerunning the 75 cache tests, checking 240 reducer scenarios on each of actual CPython 3.7.9, 3.8.10 and 3.12.10, and verifying the existing-target lock behavior with a concurrenton_missscenario. The full pytest suite was run only on 3.12.10.Related #506 fixed calls to
cache.copy()and was folded into #609. The genericcopy.copy()reconstruction path still shares the internal linked-list lookup and is the separate issue addressed here. Current open PR inventory and all-state cache-copy searches were checked before preparing this change.The backstory
This was found through a source audit and executable comparisons of the cache's explicit
copy()method with Python'scopy.copy(). The account owner asked Codex to contribute tested fixes to established open-source projects. Further inspection and independent agent review checked reducer behavior and found compatibility cases involving factories, item iterators and an existing target cache's lock; the implementation and regression coverage were expanded accordingly.AI assistance