summaryrefslogtreecommitdiffstats
path: root/Doc/library/inspect.rst
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-09-06 20:55:42 (GMT)
committerGitHub <noreply@github.com>2023-09-06 20:55:42 (GMT)
commit6f3c138dfa868b32d3288898923bbfa388f2fa5d (patch)
tree98098db4d0d2f256f2a17d515c1750a28424166c /Doc/library/inspect.rst
parent9f0c0a46f00d687e921990ee83894b2f4ce8a6e7 (diff)
downloadcpython-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 'Doc/library/inspect.rst')
-rw-r--r--Doc/library/inspect.rst11
1 files changed, 8 insertions, 3 deletions
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 603ac32..fe0ed13 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -689,8 +689,8 @@ function.
The optional *return_annotation* argument, can be an arbitrary Python object,
is the "return" annotation of the callable.
- Signature objects are *immutable*. Use :meth:`Signature.replace` to make a
- modified copy.
+ Signature objects are *immutable*. Use :meth:`Signature.replace` or
+ :func:`copy.replace` to make a modified copy.
.. versionchanged:: 3.5
Signature objects are picklable and :term:`hashable`.
@@ -746,6 +746,9 @@ function.
>>> str(new_sig)
"(a, b) -> 'new return anno'"
+ Signature objects are also supported by generic function
+ :func:`copy.replace`.
+
.. classmethod:: Signature.from_callable(obj, *, follow_wrapped=True, globalns=None, localns=None)
Return a :class:`Signature` (or its subclass) object for a given callable
@@ -769,7 +772,7 @@ function.
.. class:: Parameter(name, kind, *, default=Parameter.empty, annotation=Parameter.empty)
Parameter objects are *immutable*. Instead of modifying a Parameter object,
- you can use :meth:`Parameter.replace` to create a modified copy.
+ you can use :meth:`Parameter.replace` or :func:`copy.replace` to create a modified copy.
.. versionchanged:: 3.5
Parameter objects are picklable and :term:`hashable`.
@@ -892,6 +895,8 @@ function.
>>> str(param.replace(default=Parameter.empty, annotation='spam'))
"foo:'spam'"
+ Parameter objects are also supported by generic function :func:`copy.replace`.
+
.. versionchanged:: 3.4
In Python 3.3 Parameter objects were allowed to have ``name`` set
to ``None`` if their ``kind`` was set to ``POSITIONAL_ONLY``.