Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
orsenthil merged 2 commits intopython:masterfrombennorth:fix-issue-18533
Jan 26, 2018

Conversation

@bennorth
Copy link
Contributor

@bennorthbennorth commentedDec 12, 2017
edited by bedevere-bot
Loading

(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 aRuntimeError is raised in the case of a non-recursive but deeply nested structure. (Very similar to whattest_repr_deep() intest/test_dict.py does for a normal dict.)

https://bugs.python.org/issue18533

@the-knights-who-say-ni

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
Copy link
Member

Hum, this bug has already been fixed inhttps://bugs.python.org/issue32137 by the commit1fb72d2, no?

cc@serhiy-storchaka

@bennorth
Copy link
ContributorAuthor

The fix forbpo-32137 changed a segfault into aRecursionError. This PR proposes changing that into a friendlier"..."-style representation, i.e., no exception is raised.

(I've just noticed that my commit message incorrectly refers toRuntimeError, sorry, as this is what it was last time I looked at this. I can force-push a commit with better message if this PR is approved in principle.)

@serhiy-storchakaserhiy-storchaka added the type-featureA feature request or enhancement labelDec 12, 2017
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a 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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Add braces.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Add braces.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this needed?

@bennorth
Copy link
ContributorAuthor

@serhiy-storchaka --- I've implemented those style requests, and added a news entry.

Without this PR,OrderedDict raises aRecursionError:

>>> from collections import OrderedDict>>> d = OrderedDict()>>> d[42] = d.values()>>> repr(d)Traceback (most recent call last):  File "<stdin>", line 1, in <module>RecursionError: maximum recursion depth exceeded while getting the repr of an object

whereas with this PR:

>>> repr(d)'OrderedDict([(42, odict_values([...]))])'

The PR now adds a test for the new behaviour ofOrderedDict.

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.

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.

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
Copy link
ContributorAuthor

Thanks for feedback. New version pushed addressing comments:

  • Remove vertical whitespace;
  • Avoid relying on particular implementation in tests;
  • MoveOrderedDict test to more sensible location.

Also word 'news' entry more concisely.

@bennorth
Copy link
ContributorAuthor

Is there anything further I should be doing to help this along? Thefailing AppVeyor build looks unrelated as it's a failure indistutils.tests.test_bdist_wininst.BuildWinInstTestCase.

@bennorth
Copy link
ContributorAuthor

@terryjreedy — Thanks for bringing this up-to-date withmaster; good that the AppVeyor build is now OK.

@orsenthilorsenthil merged commitd7773d9 intopython:masterJan 26, 2018
@orsenthil
Copy link
Member

I merged it,@bennorth. All the requirements were met and thanks for your contribution.

@miss-islington
Copy link
Contributor

Thanks@bennorth for the PR, and@orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks@bennorth for the PR, and@orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-5348 is a backport of this pull request to the3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJan 26, 2018
…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
Copy link
Contributor

Sorry,@bennorth and@orsenthil, I could not cleanly backport this to2.7 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker d7773d92bd11640a8c950d6c36a9cef1cee36f96 2.7

@bennorth
Copy link
ContributorAuthor

@orsenthil — thanks for merging.

As suggested incomment on issue, I've created#5357 to backport this to 2.7.

miss-islington added a commit that referenced this pull requestFeb 26, 2018
…-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)
bennorth added a commit to bennorth/cpython that referenced this pull requestFeb 26, 2018
…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)
serhiy-storchaka pushed a commit that referenced this pull requestFeb 26, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@rhettingerrhettingerAwaiting requested review from rhettinger

Assignees

@orsenthilorsenthil

Labels

type-featureA feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@bennorth@the-knights-who-say-ni@vstinner@orsenthil@miss-islington@bedevere-bot@serhiy-storchaka@terryjreedy

[8]ページ先頭

©2009-2025 Movatter.jp