Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.6] bpo-29532: Altering a kwarg dictionary passed to functools.partial() … #209

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def func(a=10, b=20):
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
Expand Down
13 changes: 13 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

22807, 29576 and 29534 were master-only changes and they shouldn't be listed in 3.6 branch.

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.
Expand Down
5 changes: 4 additions & 1 deletion Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down