]> granicus.if.org Git - python/commitdiff
bpo-29532: Altering a kwarg dictionary passed to functools.partial() no longer affect...
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 21 Feb 2017 16:18:27 +0000 (18:18 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2017 16:18:27 +0000 (18:18 +0200)
Lib/test/test_functools.py
Misc/NEWS
Modules/_functoolsmodule.c

index 824549b80342ed8f72483208a4baa892c8b6c715..b7d648d0b15a553840c5aaf29cf42f1d1bb6d1be 100644 (file)
@@ -89,6 +89,15 @@ class TestPartial:
         p(b=7)
         self.assertEqual(d, {'a':3})
 
+    def test_kwargs_copy(self):
+        # Issue #29532: Altering a kwarg dictionary passed to a constructor
+        # should not affect a partial object after creation
+        d = {'a': 3}
+        p = self.partial(capture, **d)
+        self.assertEqual(p(), ((), {'a': 3}))
+        d['a'] = 5
+        self.assertEqual(p(), ((), {'a': 3}))
+
     def test_arg_combinations(self):
         # exercise special code paths for zero args in either partial
         # object or the caller
index d5bbd835aa21a6257134317f79f01f496d42d751..83b316c644d72bc61e3ce8f0dc5bd51af6e5b550 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,19 @@ Extension Modules
 Library
 -------
 
+- bpo-29532: Altering a kwarg dictionary passed to functools.partial()
+  no longer affects a partial object after creation.
+
+- bpo-22807: Add uuid.SafeUUID and uuid.UUID.is_safe to relay information from
+  the platform about whether generated UUIDs are generated with a
+  multiprocessing safe method.
+
+- bpo-29576: Improve some deprecations in importlib. Some deprecated methods
+  now emit DeprecationWarnings and have better descriptive messages.
+
+- bpo-29534: Fixed different behaviour of Decimal.from_float()
+  for _decimal and _pydecimal. Thanks Andrew Nester.
+
 - Issue #28556: Various updates to typing module: typing.Counter, typing.ChainMap,
   improved ABC caching, etc. Original PRs by Jelle Zijlstra, Ivan Levkivskyi,
   Manuel Krebber, and Ćukasz Langa.
index f785a7260e6a2e07954f104ebaa3e59b3ed24560..7abc9f464027f7712dc4a021bcf51e5d55c5fdc3 100644 (file)
@@ -88,10 +88,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
         if (kw == NULL) {
             pto->kw = PyDict_New();
         }
-        else {
+        else if (Py_REFCNT(kw) == 1) {
             Py_INCREF(kw);
             pto->kw = kw;
         }
+        else {
+            pto->kw = PyDict_Copy(kw);
+        }
     }
     else {
         pto->kw = PyDict_Copy(pkw);