classification
Title: functools.partial is not compatible between 2.7 and 3.5
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, naoyuki, rhettinger, serhiy.storchaka, steven.daprano
Priority: normal Keywords: patch

Created on 2017-02-11 07:20 by naoyuki, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
partial-copy-kwargs.patch serhiy.storchaka, 2017-02-11 11:10 review
Pull Requests
URL Status Linked Edit
PR 190 merged serhiy.storchaka, 2017-02-20 09:08
PR 198 closed serhiy.storchaka, 2017-02-20 12:17
PR 209 open serhiy.storchaka, 2017-02-21 06:25
PR 222 merged serhiy.storchaka, 2017-02-21 20:42
PR 703 larry, 2017-03-17 21:00
PR 552 closed dstufft, 2017-03-31 16:36
Messages (8)
msg287594 - (view) Author: Naoyuki Kamo (naoyuki) Date: 2017-02-11 07:20
The code:
from functools import partial
def f(a):
    print(a)
d = {'a': 3}
g = partial(f, **d)
g()
d['a'] = 5 
g()

On python2.7, gets
3
but on python3.5, gets
5

is it a bug?
msg287595 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2017-02-11 08:26
Confirmed that in Python 2.7 calling g() before and after modifying the dict prints 3 both times; calling g() before modifying the dict prints 3, then after modifying it prints 5.

Python 3.3 behaves like 2.7, so this sounds like a regression in 3.5 or maybe 3.4.
msg287598 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-11 11:10
Yes, this can be considered a bug. Following patch fixes it.
msg287673 - (view) Author: INADA Naoki (inada.naoki) * (Python committer) Date: 2017-02-13 10:33
patch LGTM.
msg287832 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-02-15 09:51
Agree that this is a bug.  Patch and test looks good.
msg288197 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-20 12:04
New changeset 9639e4ab6d5bd3ca0ab34fef127e9fc84b6b88b9 by GitHub in branch 'master':
bpo-29532: Altering a kwarg dictionary passed to functools.partial() (#190)
https://github.com/python/cpython/commit/9639e4ab6d5bd3ca0ab34fef127e9fc84b6b88b9
msg288309 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-21 16:18
New changeset e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965 by GitHub in branch '3.6':
bpo-29532: Altering a kwarg dictionary passed to functools.partial() no longer affects a partial object after creation. (#209)
https://github.com/python/cpython/commit/e48fd93bbb36c6d80aa4eb6af09f58c69d8cf965
msg288347 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-22 09:46
New changeset 5010a77a4da76d8d3fd861a63a7f1ce8f0e9c520 by GitHub in branch '3.5':
[3.5] bpo-29532: Altering a kwarg dictionary passed to functools.partial() no longer affects a partial object after creation. (#222)
https://github.com/python/cpython/commit/5010a77a4da76d8d3fd861a63a7f1ce8f0e9c520
History
Date User Action Args
2017-03-31 16:36:21dstufftsetpull_requests: + pull_request950
2017-03-17 21:00:35larrysetpull_requests: + pull_request612
2017-02-22 09:53:25serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-02-22 09:46:35serhiy.storchakasetmessages: + msg288347
2017-02-21 20:42:50serhiy.storchakasetpull_requests: + pull_request186
2017-02-21 16:18:31serhiy.storchakasetmessages: + msg288309
2017-02-21 06:25:22serhiy.storchakasetpull_requests: + pull_request178
2017-02-20 12:17:41serhiy.storchakasetpull_requests: + pull_request165
2017-02-20 12:04:32serhiy.storchakasetmessages: + msg288197
2017-02-20 09:08:20serhiy.storchakasetpull_requests: + pull_request156
2017-02-15 09:51:49rhettingersetnosy: + rhettinger
messages: + msg287832
2017-02-13 10:33:33inada.naokisetnosy: + inada.naoki
messages: + msg287673
2017-02-11 11:10:13serhiy.storchakasetfiles: + partial-copy-kwargs.patch

components: + Library (Lib)
versions: + Python 3.7, - Python 3.4
keywords: + patch
nosy: + serhiy.storchaka

messages: + msg287598
stage: patch review
2017-02-11 08:26:31steven.dapranosetnosy: + steven.daprano

messages: + msg287595
versions: + Python 3.4, Python 3.6
2017-02-11 07:20:01naoyukicreate