Repository navigation
fix(corekit): copying or pickling a stream proxy no longer recurses (#1524) - #1544
Merged
Merged
Conversation
…1524) * `PeekableStream.__getattr__` forwarded every missing name to `self._stream`. `copy` and `pickle` build the instance without `__init__`, so `_stream` was unset and its lookup re-entered `__getattr__` until `RecursionError`. It now raises `AttributeError` for `_stream` and for any dunder, so the proxy's own protocols are never replaced by the stream's. * The default protocols then apply: `copy.copy` shares the stream, `copy.deepcopy` and `pickle` copy it, and so work exactly when the stream's own do. The class docstring states this. * `NamedStream` has no `__getattr__` and `SeekableReader` refuses copying as `io.BufferedReader` does; neither changes. New tests in `tests/corekit/test_io_peekable_stream_copy_1524_unit.py` cover copy, deepcopy and pickle protocols 0-5 over a `BytesIO`.
Owner
Author
|
Verdict: GOOD TO GO at
Nits, not blocking: the |
Contributor
|
Coverage: 90.09% (unit tier, Python 3.14,
Per-file detail: the |
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.
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort)make testpasses, and a test case covers the change — tests added; rantests/corekit,tests/foundation/test_extraction*.py, the PyPCAPFile engine,tests/project, the docstring contract and the tier guard, not the full suiteAdded a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
copyandpicklebuild aPeekableStreamwithout__init__.__getattr__then forwarded__setstate__to an unset_stream, whose own lookup re-entered__getattr__untilRecursionError. It now refuses_streamand every dunder, so the proxy's protocols are never the stream's.Semantics:
copy.copyshares the stream (one position);copy.deepcopyandpicklecopy it, so they succeed exactly when the stream's own do —BytesIOfrom protocol 2, an open file never.NamedStreamandSeekableReaderwere already sound and are unchanged.tests/corekit/test_io_peekable_stream_copy_1524_unit.py: 7 tests; 9 of 11 results fail on945c3c3d8(8RecursionError, 1 forwarded__setstate__).Closes #1524