From 2d88e63bfcf7bccba925ab80b3f47ccf8b7aefa8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 26 Jun 2019 19:07:44 +0300 Subject: bpo-37163: Make the obj argument of dataclasses.replace() a positional-only. (GH-14390) --- Doc/library/dataclasses.rst | 2 +- Lib/dataclasses.py | 2 +- Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index db5c3e0..9e02882 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 b035cbb..5e57e20 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -1206,7 +1206,7 @@ def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, 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 0000000..07182e7 --- /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. -- cgit v0.12