classification
Title: HTTPConnection.requests has a mutable as default value for headers
Type: Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, martin.panter, matrixise, r.david.murray
Priority: normal Keywords: patch

Created on 2016-08-10 17:58 by matrixise, last changed 2017-05-24 12:42 by matrixise. This issue is now closed.

Files
File name Uploaded Description Edit
issue27728.diff matrixise, 2016-08-10 17:59 review
Messages (7)
msg272352 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2016-08-10 17:58
http.client.HTTPConnection.request, the argument 'headers' has a default value, and this one is a mutable (dict).
msg272353 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2016-08-10 17:59
here is my patch for that.
msg272356 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-08-10 18:11
Why is that an issue?
msg272359 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-08-10 18:53
Well, it's a problem in general because if the called routine modifies the default dict...the default is modified.  I'm guessing it is never modified, but it is indeed better future proofing of the code to not use a mutable default in a routine that passes the variable to other functions, as this one does.
msg272364 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2016-08-10 19:20
Thanks R.David.Murray,

@SilentGhost in fact, in this code, it's not an issue but we use a bad practice and not a good practice with a mutable value.
msg272380 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-08-10 22:36
If the code does happen to mutate the dictionary, there would still be a bug with modifying any dictionary passed in by the caller. But I suspect there is no bug. So I am not sure the change is worth it. If we do go ahead, the documentation needs updating to say None is now allowed.
msg272389 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-08-11 00:36
Yes, this is one of those cases where the benefit of the change is probably outweighed by the cost.
History
Date User Action Args
2017-05-24 12:42:53matrixisesetstatus: open -> closed
stage: patch review -> resolved
2017-05-24 12:42:35matrixisesetresolution: not a bug
2016-08-11 00:36:32r.david.murraysetmessages: + msg272389
2016-08-10 22:36:12martin.pantersetnosy: + martin.panter
messages: + msg272380
2016-08-10 20:11:26matrixisesetstage: patch review
2016-08-10 19:20:50matrixisesetmessages: + msg272364
2016-08-10 18:53:43r.david.murraysetnosy: + r.david.murray
messages: + msg272359
2016-08-10 18:11:55SilentGhostsetnosy: + SilentGhost
messages: + msg272356
2016-08-10 17:59:04matrixisesetfiles: + issue27728.diff
keywords: + patch
messages: + msg272353
2016-08-10 17:58:34matrixisecreate