Repository navigation
Conversation
The __reversed__ methods of dict, dict_keys, dict_items and dict_values wrapped the reverse storage iterator with the forward factories, so reversed(d) was a dict_keyiterator and type(reversed(d)) is type(iter(d)) held. The PDictReverse*Iterator types were still defined and registered with IteratorBuiltins, but nothing created them since afc1f12 dropped the reverse factories. Restore createDictReverse{Key,Item,Value}Iterator in their former shape and use them at the four sites, as CPython builds these iterators from the PyDictRevIter*_Type types. Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
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.
Description
Fixes #1226
The
__reversed__methods ofdict,dict_keys,dict_itemsanddict_valueswrapped the reverse storage iterator with the forward factories, so the result was adict_keyiterator,dict_valueiteratorordict_itemiterator. ThePDictReverse*Iteratortypes are still defined and registered withIteratorBuiltins, but nothing has created them since afc1f12 removed their factories. CPython builds all four from thePyDictRevIter*_Typetypes (dictobject.c#L4494).AS-IS
TO-BE
(matching CPython)
Changes
PFactory.createDictReverse{Key,Item,Value}Iteratorin their pre-afc1f123e6 shape, building the same Java iterator objects with the reverse types.DictBuiltins.ReversedNode,DictViewBuiltins.ReversedNode(keys and items) andDictValuesBuiltins.ReversedNode.test_reversed_iterator_typestotests/test_dict.py.The reverse types need no
disallowInstantiation():PythonBuiltinClassTypealready sets it for a builtin type withouttp_newwhose base isobject, so calling one raisesTypeErroras in CPython, which the new test checks.Testing
mx python-jvmon linux-aarch64, thenmx graalpytest test_dict.py test_ordered_dict.py test_iterator.py test_map_strategies.py(110 passed).test.test_dict,test.test_dictviewsandtest.test_ordered_dictfromlib-pythongive the same per-test results as on master. The new test fails on the unpatched build. For all fourreversed()calls, the type name, iteration order,__length_hint__,__reduce__, pickling and instantiation now match CPython 3.12.13.