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

GH-134863: Add reversible keys, values, items views to collections.abc builtin library#134877

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

Open
t1m013y wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromt1m013y:GH-134863

Conversation

t1m013y
Copy link

GH-134863

Madecollections.abc.Mapping's keys, values, items views reversible by adding__reversed__ method

@python-cla-bot
Copy link

python-cla-botbot commentedMay 29, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@rhettingerrhettinger self-assigned thisMay 29, 2025
Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

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

We need a test case for this, and the docs need to be updated.

…Ql1kn.rstCo-authored-by: Peter Bierma <zintensitydev@gmail.com>
@rhettinger
Copy link
Contributor

Please read the maintenance notes at the top of this file.

@t1m013y
Copy link
Author

t1m013y commentedMay 29, 2025
edited
Loading

Please read the maintenance notes at the top of this file.

Will it be OK to add new ABCs (for example,ReversibleMapping andMutableReversibleMapping) and new keys, values, items views for them? I can create a new pull request for this.

@rhettinger
Copy link
Contributor

rhettinger commentedMay 29, 2025
edited
Loading

Will it be OK to add new ABCs

That would work, but it doesn't seem worth it. There is almost zero benefit. These ABCs have been around a long time and no one has missed the reversible spec. Likely, this is because the concretedict class's reversible feature is rarely used.

In general, the ABCs are intentionally not full featured. The intent of the ABCs was to be a minimal spec. For example, MutableSet lacks union, intersection, and difference; the operators are supposed to suffice.

One other thought is that reversibility is only meaningful if the underlying mapping is ordered, but we have no way to specify or enforce an ordering requirement with ABCs so this would be on shaky ground.

@t1m013y
Copy link
Author

t1m013y commentedMay 29, 2025
edited
Loading

That would work, but it doesn't seem worth it. There is almost zero benefit. These ABCs have been around a long time and no one has missed the reversible spec. Likely, this is because the concretedict class's reversible feature is rarely used.

In general, the ABCs are intentionally not full featured. The intent of the ABCs was to be a minimal spec. For example, MutableSet lacks union, intersection, and difference; the operators are supposed to suffice.

One other thought is that reversibility is only meaningful if the underlying mapping is ordered, but we have no way to specify or enforce an ordering requirement with ABCs so this would be on shaky ground.

So do you want to say that you will not merge this PR and PR with new ABCs?

I want to add reversibility because:

  1. I think there should be ABC for ordered (hence reversible) mapping, like OrderedDict
  2. I miss this feature for my project

@t1m013y
Copy link
Author

See alsoGH-134863

dict andOrderedDict have reversed keys, values and items iterators, then, I think, ABC for ordered mapping should too (it can be a new ABC not to cause incompatibility, I read the maintenance notes).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ZeroIntensityZeroIntensityZeroIntensity left review comments

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

Assignees

@rhettingerrhettinger

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@t1m013y@rhettinger@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp