diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-02-21 16:18:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-21 16:18:27 (GMT) |
commit | e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965 (patch) | |
tree | ef1ac00e07fb896481e9314b86c039ebd4a848b4 | |
parent | 51a477c0d53b09d5e876c23288ad006ad64c1e97 (diff) | |
download | cpython-e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965.zip cpython-e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965.tar.gz cpython-e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965.tar.bz2 |
bpo-29532: Altering a kwarg dictionary passed to functools.partial() no longer affects a partial object after creation. (#209)
-rw-r--r-- | Lib/test/test_functools.py | 9 | ||||
-rw-r--r-- | Misc/NEWS | 13 | ||||
-rw-r--r-- | Modules/_functoolsmodule.c | 5 |
3 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 824549b..b7d648d 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -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 @@ -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. diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index f785a72..7abc9f4 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -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); |