Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.4k
bpo-18533: Avoid RuntimeError from repr() of recursive dictview#4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
the-knights-who-say-ni commentedDec 12, 2017
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed thePSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username onbugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please followthe steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
vstinner commentedDec 12, 2017
Hum, this bug has already been fixed inhttps://bugs.python.org/issue32137 by the commit1fb72d2, no? |
bennorth commentedDec 12, 2017
The fix forbpo-32137 changed a segfault into a (I've just noticed that my commit message incorrectly refers to |
serhiy-storchaka left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. Just fix a style and add a news entry.
What about OrderedDict? Is it fixed by this change?
Objects/dictobject.c Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Add braces.
Objects/dictobject.c Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Add braces.
Lib/test/test_dictviews.py Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is this needed?
bennorth commentedDec 13, 2017
@serhiy-storchaka --- I've implemented those style requests, and added a news entry. Without this PR, whereas with this PR: The PR now adds a test for the new behaviour of |
Objects/dictobject.c Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think empty lines are not needed after}.} itself adds enough vertical space.
Lib/test/test_collections.py Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Move this test into test_ordered_dict.py.
Lib/test/test_collections.py Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The concrete implementation is implementation dependent. For example in PyPy3 it isOrderedDict([(42, _OrderedDictValuesView(...))]). I think it enough to test that repr() doesn't raise an exception in other implementations.
r=repr(d)iftest.support.check_impl_detail(cpython=True):self.assertEqual(r,'OrderedDict([(42, odict_values([...]))])')
dictview_repr(): Use a Py_ReprEnter() / Py_ReprLeave() pair to checkfor recursion, and produce "..." if so.test_recursive_repr(): Check for the a string rather than aRecursionError. (Test cannot be any tighter as contents areimplementation-dependent.)test_deeply_nested_repr(): Add new test, replacing the originaltest_recursive_repr(). It checks that a RecursionError is raised inthe case of a non-recursive but deeply nested structure. (Verysimilar to what test_repr_deep() in test/test_dict.py does for anormal dict.)OrderedDictTests: Add new test case, to test behaviour on OrderedDictinstances containing their own values() or items().
bennorth commentedDec 13, 2017
Thanks for feedback. New version pushed addressing comments:
Also word 'news' entry more concisely. |
bennorth commentedDec 29, 2017
Is there anything further I should be doing to help this along? Thefailing AppVeyor build looks unrelated as it's a failure in |
bennorth commentedJan 25, 2018
@terryjreedy — Thanks for bringing this up-to-date with |
orsenthil commentedJan 26, 2018
I merged it,@bennorth. All the requirements were met and thanks for your contribution. |
miss-islington commentedJan 26, 2018
Thanks@bennorth for the PR, and@orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
miss-islington commentedJan 26, 2018
Thanks@bennorth for the PR, and@orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7. |
bedevere-bot commentedJan 26, 2018
GH-5348 is a backport of this pull request to the3.6 branch. |
…thonGH-4823)dictview_repr(): Use a Py_ReprEnter() / Py_ReprLeave() pair to checkfor recursion, and produce "..." if so.test_recursive_repr(): Check for the string rather than aRecursionError. (Test cannot be any tighter as contents areimplementation-dependent.)test_deeply_nested_repr(): Add new test, replacing the originaltest_recursive_repr(). It checks that a RecursionError is raised inthe case of a non-recursive but deeply nested structure. (Verysimilar to what test_repr_deep() in test/test_dict.py does for anormal dict.)OrderedDictTests: Add new test case, to test behavior on OrderedDictinstances containing their own values() or items().(cherry picked from commitd7773d9)
miss-islington commentedJan 26, 2018
Sorry,@bennorth and@orsenthil, I could not cleanly backport this to |
bennorth commentedJan 27, 2018
@orsenthil — thanks for merging. As suggested incomment on issue, I've created#5357 to backport this to 2.7. |
…-4823)dictview_repr(): Use a Py_ReprEnter() / Py_ReprLeave() pair to checkfor recursion, and produce "..." if so.test_recursive_repr(): Check for the string rather than aRecursionError. (Test cannot be any tighter as contents areimplementation-dependent.)test_deeply_nested_repr(): Add new test, replacing the originaltest_recursive_repr(). It checks that a RecursionError is raised inthe case of a non-recursive but deeply nested structure. (Verysimilar to what test_repr_deep() in test/test_dict.py does for anormal dict.)OrderedDictTests: Add new test case, to test behavior on OrderedDictinstances containing their own values() or items().(cherry picked from commitd7773d9)
…on#4823)dictview_repr(): Use a Py_ReprEnter() / Py_ReprLeave() pair to checkfor recursion, and produce "..." if so.test_recursive_repr(): Check for a string rather than aRuntimeError. (Test cannot be any tighter as contents areimplementation-dependent.)test_deeply_nested_repr(): Add new test, replacing the originaltest_recursive_repr(). It checks that a RuntimeError is raised inthe case of a non-recursive but deeply nested structure.OrderedDictTests: Add new test case, to test behavior on OrderedDictinstances containing their own viewvalues() or viewitems(). This testpasses without the patch to dictview_repr(), but it failed in (atleast some versions of) Python 3, so including it here forcompleteness.(cherry picked from commitd7773d9)
Uh oh!
There was an error while loading.Please reload this page.
(Created as perrecent comment onbpo-18533. See issue for further background and discussion.)
dictview_repr(): Use aPy_ReprEnter()/Py_ReprLeave()pair to check for recursion, and produce"..."if so.test_recursive_repr(): Check for the correct string (containing"...") rather than aRuntimeError.test_deeply_nested_repr(): Add new test, replacing the originaltest_recursive_repr(). It checks that aRuntimeErroris raised in the case of a non-recursive but deeply nested structure. (Very similar to whattest_repr_deep()intest/test_dict.pydoes for a normal dict.)https://bugs.python.org/issue18533