Skip to content

gh-155041: Support copy.replace() for decimal.Context - #155047

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:decimal-context-replace
Aug 2, 2026
Merged

gh-155041: Support copy.replace() for decimal.Context#155047
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:decimal-context-replace

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Add Context.__replace__() in both implementations, so that copy.replace() returns a duplicate of the context with the specified fields replaced. Fields which are not specified keep the values they have in the original context.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Aug 1, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33869421 | 📁 Comparing 82d2287 against main (7ce7f0b)

  🔍 Preview build  

2 files changed
± library/decimal.html
± whatsnew/changelog.html

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment on lines +1731 to +1738
prec: object = NULL
rounding: object = NULL
Emin as emin: object = NULL
Emax as emax: object = NULL
capitals: object = NULL
clamp: object = NULL
flags as status: object = NULL
traps: object = NULL

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.

The problem with NULL defaults, is that this not supported by inspect.signature(), rendered as "unrepresentable".

But perhaps it for another day, we have other examples in the decimal module. Using a sentinel might be an option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is why we use @text_signature "($self, /, **changes)" like for all other __replace__ methods.

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.

This is a workaround, yes. Hence, PR was approved.

But I think that explicit arguments would be better.

@serhiy-storchaka
serhiy-storchaka merged commit 3f4ed1d into python:main Aug 2, 2026
53 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the decimal-context-replace branch August 2, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants