diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index db5c3e0c7e2893..9e0288290203dd 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -356,7 +356,7 @@ Module-level decorators, classes, and functions def add_one(self): return self.x + 1 -.. function:: replace(instance, **changes) +.. function:: replace(instance, /, **changes) Creates a new object of the same type of ``instance``, replacing fields with values from ``changes``. If ``instance`` is not a Data diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index b035cbb809f848..5e57e200847f0a 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -1206,7 +1206,7 @@ class C(Base): unsafe_hash=unsafe_hash, frozen=frozen) -def replace(obj, **changes): +def replace(obj, /, **changes): """Return a new object replacing specified fields with new values. This is especially useful for frozen classes. Example usage: diff --git a/Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst b/Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst new file mode 100644 index 00000000000000..07182e7675d11d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst @@ -0,0 +1 @@ +The *obj* argument of :func:`dataclasses.replace` is positional-only now.