Add MappingView.mapping for parity with dictview #28892
Closed
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 of gh-20749, built-in dictviews now have a
mappingattribute.This PR adds the same to
collections.abc.MappingView, so that non-builtin mappings can get feature parity, not to mention a consistent interface, just by inheriting fromcollections.abc.Mapping(as many already do), without having to add any boilerplate code of their own.From the associated original issue bpo-40890, it looks like this was never discussed or considered. Perhaps this would have been added at the same time as gh-20749 if it had been part of the original discussion. Submitting this (currently draft) 3-line PR as a starting point for further discussion. The changes in this PR already make the following code work:
$ ./python.exe -VV Python 3.11.0a1+ (heads/main-dirty:7103356455, Oct 11 2021, 17:28:12) [Clang 12.0.0 (clang-1200.0.32.29)] $ ./python.exe -m doctest demo.txt # no output + exits zero => it worksIf it makes sense to pursue this, I can create a proper bpo issue and put the finishing touches on this PR.
Context: I noticed this while reviewing the changes in Python 3.10 to see if they called for any corresponding changes to my bidict library, which I believe is one of several libraries that would benefit from fixing this issue.
/cc @rhettinger @sweeneyde et al.