diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-09-06 20:55:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 20:55:42 (GMT) |
commit | 6f3c138dfa868b32d3288898923bbfa388f2fa5d (patch) | |
tree | 98098db4d0d2f256f2a17d515c1750a28424166c /Lib/inspect.py | |
parent | 9f0c0a46f00d687e921990ee83894b2f4ce8a6e7 (diff) | |
download | cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.zip cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.tar.gz cpython-6f3c138dfa868b32d3288898923bbfa388f2fa5d.tar.bz2 |
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.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index c821183..aaa22be 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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) |