[Python-checkins] bpo-37163: Make the obj argument of dataclasses.replace() a positional-only. (GH-14390)

Serhiy Storchaka webhook-mailer at python.org
Wed Jun 26 12:07:48 EDT 2019


https://github.com/python/cpython/commit/2d88e63bfcf7bccba925ab80b3f47ccf8b7aefa8
commit: 2d88e63bfcf7bccba925ab80b3f47ccf8b7aefa8
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-06-26T19:07:44+03:00
summary:

bpo-37163: Make the obj argument of dataclasses.replace() a positional-only. (GH-14390)

files:
A Misc/NEWS.d/next/Library/2019-06-19-10-35-53.bpo-37163.9pPg2F.rst
M Doc/library/dataclasses.rst
M Lib/dataclasses.py

diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index db5c3e0c7e28..9e0288290203 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 b035cbb809f8..5e57e200847f 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 000000000000..07182e7675d1
--- /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.



More information about the Python-checkins mailing list