Skip to content

gh-142085: Avoid raising in ChainMap.__ior__ before trying other.__ror__#142087

Closed
ChuheLin wants to merge 8 commits intopython:mainfrom
ChuheLin:gh-142085-fix-chainmap-ior
Closed

gh-142085: Avoid raising in ChainMap.__ior__ before trying other.__ror__#142087
ChuheLin wants to merge 8 commits intopython:mainfrom
ChuheLin:gh-142085-fix-chainmap-ior

Conversation

@ChuheLin
Copy link
Copy Markdown

@ChuheLin ChuheLin commented Nov 29, 2025

Fixes #142085. ChainMap's __ior__ method now returns NotImplemented instead of raising TypeError when update fails, allowing the fallback to __ror__ to work correctly.

@ChuheLin ChuheLin requested a review from rhettinger as a code owner November 29, 2025 14:20
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Nov 29, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Nov 29, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

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

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Nov 29, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

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

1 similar comment
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Nov 29, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

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

@ChuheLin ChuheLin force-pushed the gh-142085-fix-chainmap-ior branch from a3f5094 to f2826a9 Compare November 29, 2025 14:41
Comment thread Lib/collections/__init__.py
@@ -0,0 +1 @@
Fix ``ChainMap.__ior__`` to return ``NotImplemented`` instead of raising ``TypeError`` for unsupported types.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Fix ``ChainMap.__ior__`` to return ``NotImplemented`` instead of raising ``TypeError`` for unsupported types.
Fix :class:`ChainMap.__ior__ <collections.ChainMap>` to return :data:`NotImplemented`
instead of raising :exc:`TypeError`` for unsupported types.

We still want something we can click on even if it's the expected method.

…u8i9o.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Nov 29, 2025

Sorry I added two backticks in my suggestion!

Comment thread Misc/NEWS.d/next/Library/2025-11-29-22-23-00.gh-issue-142085.7u8i9o.rst Outdated
…u8i9o.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz picnixz changed the title gh-142085: Fix ChainMap.__ior__ to return NotImplemented for unsuppor… gh-142085: Avoid raising in ChainMap.__ior__ before trying other.__ror__ Nov 29, 2025
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Nov 29, 2025

Considering that this would create an exceptional case (see #142085 (comment)), we are going to close this one until support has been gathered for that change. Sorry for the false hope but thank you for pointing out this.

@picnixz picnixz closed this Nov 29, 2025
@ChuheLin
Copy link
Copy Markdown
Author

"Thanks for the detailed explanation @serhiy-storchaka. I understand now that ChainMap should strictly follow dict's behavior, even regarding this limitation. I learned a lot from this process!"

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChainMap.__ior__ raises TypeError instead of returning NotImplemented for unsupported types

2 participants