| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,15 @@ def func(a=10, b=20): | |||
| 80 | 80 | p(b=7) | |
| 81 | 81 | self.assertEqual(d, {'a':3}) | |
| 82 | 82 | ||
| 83 | + def test_kwargs_copy(self): | ||
| 84 | + # Issue #29532: Altering a kwarg dictionary passed to a constructor | ||
| 85 | + # should not affect a partial object after creation | ||
| 86 | + d = {'a': 3} | ||
| 87 | + p = self.partial(capture, **d) | ||
| 88 | + self.assertEqual(p(), ((), {'a': 3})) | ||
| 89 | + d['a'] = 5 | ||
| 90 | + self.assertEqual(p(), ((), {'a': 3})) | ||
| 91 | + | ||
| 83 | 92 | def test_arg_combinations(self): | |
| 84 | 93 | # exercise special code paths for zero args in either partial | |
| 85 | 94 | # object or the caller | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,9 @@ Extension Modules | |||
| 32 | 32 | Library | |
| 33 | 33 | ------- | |
| 34 | 34 | ||
| 35 | + - bpo-29532: Altering a kwarg dictionary passed to functools.partial() | ||
| 36 | + no longer affects a partial object after creation. | ||
| 37 | + | ||
| 35 | 38 | - Issue #28556: Various updates to typing module: typing.Counter, typing.ChainMap, | |
| 36 | 39 | improved ABC caching, etc. Original PRs by Jelle Zijlstra, Ivan Levkivskyi, | |
| 37 | 40 | Manuel Krebber, and Łukasz Langa. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,10 +88,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | |||
| 88 | 88 | if (kw == NULL) { | |
| 89 | 89 | pto->kw = PyDict_New(); | |
| 90 | 90 | } | |
| 91 | - else { | ||
| 91 | + else if (Py_REFCNT(kw) == 1) { | ||
| 92 | 92 | Py_INCREF(kw); | |
| 93 | 93 | pto->kw = kw; | |
| 94 | 94 | } | |
| 95 | + else { | ||
| 96 | + pto->kw = PyDict_Copy(kw); | ||
| 97 | + } | ||
| 95 | 98 | } | |
| 96 | 99 | else { | |
| 97 | 100 | pto->kw = PyDict_Copy(pkw); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments