mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
gh-108751: Add copy.replace() function (GH-108752)
It creates a modified copy of an object by calling the object's __replace__() method. It is a generalization of dataclasses.replace(), named tuple's _replace() method and replace() methods in various classes, and supports all these stdlib classes.
This commit is contained in:
parent
9f0c0a46f0
commit
6f3c138dfa
19 changed files with 311 additions and 68 deletions
|
@ -2870,6 +2870,8 @@ class Parameter:
|
|||
|
||||
return formatted
|
||||
|
||||
__replace__ = replace
|
||||
|
||||
def __repr__(self):
|
||||
return '<{} "{}">'.format(self.__class__.__name__, self)
|
||||
|
||||
|
@ -3130,6 +3132,8 @@ class Signature:
|
|||
return type(self)(parameters,
|
||||
return_annotation=return_annotation)
|
||||
|
||||
__replace__ = replace
|
||||
|
||||
def _hash_basis(self):
|
||||
params = tuple(param for param in self.parameters.values()
|
||||
if param.kind != _KEYWORD_ONLY)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue