Skip to content

refactor(version): use explicit keywords in __replace__ - #1378

Open
henryiii wants to merge 1 commit into
pypa:mainfrom
henryiii:version-replace-signature
Open

refactor(version): use explicit keywords in __replace__#1378
henryiii wants to merge 1 commit into
pypa:mainfrom
henryiii:version-replace-signature

Conversation

@henryiii

@henryiii henryiii commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Using an explicit sentinel instead of kw-only args.

🤖 AI text below 🤖

Benefits:

  • Unknown keyword arguments now raise TypeError. Before, a typo such as v.__replace__(prerelease=("a", 1)) was silently ignored.
  • The signature is introspectable (help(), IDEs) without the **kwargs indirection. The docstring signature line is kept so autodoc does not render the sentinel default.
  • The private _VersionReplace TypedDict and the typing_extensions.Unpack import are removed.

None keeps its meaning of clearing a field, and the no-change return self short-circuit is unchanged. The pre-3.13 replace() test shim no longer uses a Protocol, since a method with named keyword-only parameters does not satisfy a **kwargs protocol.

Replace the **kwargs / Unpack[TypedDict] signature with explicit
keyword-only parameters and a sentinel default. Unknown keyword
arguments now raise TypeError instead of being silently ignored, the
signature is introspectable, and the _VersionReplace TypedDict and
typing_extensions Unpack import are no longer needed. None keeps its
meaning of clearing a field.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii marked this pull request as ready for review August 10, 2026 05:40

@shinzoxD shinzoxD left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified head b5c3f08. The explicit sentinel-backed keyword-only signature preserves no-op identity, clearing semantics, normalization/validation, and copy.replace behavior while rejecting unknown keywords. Locally, tests/test_version.py completed with 51,524 passed; Nox's final nonzero status was only the expected repository-wide 100% coverage gate after selecting one test file. git diff --check is clean, and all upstream CI checks are green. The versionchanged 26.4 note documents the observable behavior.

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