[2.7] bpo-18533: Avoid RuntimeError from repr() of recursive dictview [GH-4823]#5357
Merged
Merged
Conversation
Member
|
I have executed the tests with and there is no reference leaks. |
Member
There was a problem hiding this comment.
Py_DECREF(seq) could be called just after PyObject_Repr(). This will simplify the code.
Contributor
Author
There was a problem hiding this comment.
Thanks for suggestion; that is indeed cleaner. I've just force-pushed a fresh commit including that change.
…on#4823) dictview_repr(): Use a Py_ReprEnter() / Py_ReprLeave() pair to check for recursion, and produce "..." if so. test_recursive_repr(): Check for a string rather than a RuntimeError. (Test cannot be any tighter as contents are implementation-dependent.) test_deeply_nested_repr(): Add new test, replacing the original test_recursive_repr(). It checks that a RuntimeError is raised in the case of a non-recursive but deeply nested structure. OrderedDictTests: Add new test case, to test behavior on OrderedDict instances containing their own viewvalues() or viewitems(). This test passes without the patch to dictview_repr(), but it failed in (at least some versions of) Python 3, so including it here for completeness. (cherry picked from commit d7773d9)
5b4fdb5 to
a27a0d4
Compare
serhiy-storchaka
approved these changes
Feb 26, 2018
|
@serhiy-storchaka: Please replace |
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.
As suggested in a message on BPO, this is a backport of #4823 to the 2.7 branch. Compared to the changes introduced in #4823, this PR:
seq_strindictview_repr().PyString...(instead ofPyUnicode...).viewvalues()andviewitems()(instead ofvalues()anditems()).RuntimeError(instead ofRecursionError).I kept the test on
OrderedDicteven though 2.7 behaves correctly already; please let me know if it would be cleaner to omit this part.https://bugs.python.org/issue18533