Issue 22609: Constructors of some mapping classes don't accept self keyword argument (original) (raw)

Created on 2014-10-11 12:04 by abacabadabacaba, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
collections_pos_only_params.patch serhiy.storchaka,2014-10-11 14:12 review
collections_pos_only_params2.patch serhiy.storchaka,2014-10-12 06:57 review
UserDict_self_and_dict_keywords.patch serhiy.storchaka,2015-03-25 18:46 review
UserDict_self_and_dict_keywords_2.patch serhiy.storchaka,2015-03-31 05:28 review
UserDict_self_and_dict_keywords_3.patch serhiy.storchaka,2015-06-26 17:59 review
Messages (34)
msg229076 - (view) Author: Evgeny Kapun (abacabadabacaba) Date: 2014-10-11 12:04
>>> import collections >>> collections.Counter(self=1) Traceback (most recent call last): File "", line 1, in TypeError: __init__() got multiple values for argument 'self' >>> collections.OrderedDict(self="test") Traceback (most recent call last): File "", line 1, in TypeError: __init__() got multiple values for argument 'self' >>> collections.UserDict(self="test") Traceback (most recent call last): File "", line 1, in TypeError: __init__() got multiple values for argument 'self' Python surely should have positional-only parameters.
msg229089 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-10-11 14:12
Here is a patch.
msg229098 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-10-11 17:10
I'll spend some time taking this one under consideration. Keyword arguments for dicts and dict-like classes are already somewhat limited (only non-keyword identifiers) that why Guido resisted adding them in the first place. And, in the context of OrderedDicts, they aren't really useful at all (because the order gets scrambled). I'm reluctant to make the number of changes required in order to support this corner case. The ship for Python 2.7 sailed a long time ago and it is risky to make changes like this. After the patch, the code is less readable, harder to get right, harder to maintain, and not as performant. On the other hand, adding "self" would be a nice-to-have, so it is worth thinking about.
msg229118 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-10-12 06:15
After some thought, I think we have to fix this. I'll go through the patch in careful detail this weekend. Ethan, if you would like to help, it would be great to have a third pair of eyes looking at the patch to make sure it correct it every detail.
msg229121 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-10-12 06:57
I thought that more verbose but straightforward code would be more acceptable. Well, here is smaller and clever patch. Tests are the same.
msg229189 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-10-12 18:43
I will take a look.
msg229248 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-10-13 15:27
Code looks good. Only downside is the change in help and inspect.signature output, but that is minor: Help on dict object: class dict(object) [...] | __init__(self, /, *args, **kwargs) vs. Help on class Counter in module collections: class Counter(builtins.dict) [...] __init__(*args, **kwds) +1 to accept.
msg229249 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-10-13 16:32
FWIW, I agree that it should be fixed: >>> dict(self=1) {'self': 1}
msg231753 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-11-27 06:47
This looks good. Go ahead and apply the first version of the patch.
msg231763 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-27 14:54
New changeset 816c15fe5812 by Serhiy Storchaka in branch '3.4': Issue #22609: Constructors and update methods of mapping classes in the https://hg.python.org/cpython/rev/816c15fe5812 New changeset 88ab046fdd8a by Serhiy Storchaka in branch 'default': Issue #22609: Constructors and update methods of mapping classes in the https://hg.python.org/cpython/rev/88ab046fdd8a
msg231765 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-27 15:51
New changeset cd1ead4feddf by Serhiy Storchaka in branch '3.4': Issue #22609: Revert changes in UserDict. They conflicted with existing tests. https://hg.python.org/cpython/rev/cd1ead4feddf New changeset 167d51a54de2 by Serhiy Storchaka in branch 'default': Issue #22609: Revert changes in UserDict. They conflicted with existing tests. https://hg.python.org/cpython/rev/167d51a54de2
msg231766 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-27 16:00
Unfortunately there is existing test for current behavior of UserDict: self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]), d2) This looks wrong to me and I think we should break compatibility here.
msg231769 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-27 17:05
New changeset 3dfe4f0c626b by Serhiy Storchaka in branch '2.7': Issue #22609: Constructors and update methods of mapping classes in the https://hg.python.org/cpython/rev/3dfe4f0c626b
msg231915 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-01 08:58
So what to do wish UserDict? Should we break backward compatibility and add support for "self" and "dict" keywords as in other dict-like types?
msg231936 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-12-01 12:42
Fix `self` now, add a warning and single minor cycle deprecation period for 'dict'.
msg232353 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-12-09 08:38
[Serhiy] > So what to do wish UserDict? I'm leaning in favor of leaving UserDict as-is. AFAICT, in the very long history of UserDict, this has never been a problem. So, I don't think there is an issue worth breaking the published API and possibly breaking code that currently works. (This is a case of practicality beating purity).
msg234875 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-01-28 09:02
So may be close this issue? See also .
msg239278 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-25 18:46
Here is a patch for UserDict, that keep current behavior, but allows to pass keys "self" and "dict" if positional parameter dict is specified. >>> UserDict(self=42) {'self': 42} >>> UserDict({}, dict=42) {'dict': 42} >>> UserDict(dict={'a': 42}) {'a': 42}
msg239655 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-03-31 02:19
UserDict_self_and_dict_keywords.patch looks good to me. Is there a reason not to use assertWarnsRegex? Also, there are already collections.UserDict() usages in the test file, so I'd remove the "from collections import UserDict" import.
msg239667 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-31 05:28
Thank you for your review Berker. > Is there a reason not to use assertWarnsRegex? Initially the patch was written for 2.7. Fixing WeakValueDictionary in 2.7 needs first fix UserDict (). That is why I returned to this issue. > Also, there are already collections.UserDict() usages in the test file, so > I'd remove the "from collections import UserDict" import. These tests originally was written for test_collections. Updated patch addresses Berker's comment.
msg243329 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-16 16:11
Could you please look at the new patch Raymond? This is the dependency for .
msg244470 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-30 16:17
Ping.
msg244503 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-05-31 00:20
Left a couple pedantic comments.
msg245859 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-06-26 17:59
Updated patch addresses Martin's comments.
msg245877 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-27 02:49
Left some feedback in the code review.
msg245944 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-29 15:35
Patch looks fine to me. I understand Yury withdrew his comment.
msg246936 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-07-19 10:16
Ping again.
msg246954 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-07-20 04:20
Who are you pinging? I did just notice a minor English grammar problem (“one arguments”). But as far as I am concered you could have already committed the patch.
msg246956 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-07-20 04:46
I will look at this more when I get a chance (likely this week).
msg246957 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-07-20 05:11
I was pinging Raymond. He is maintainer of the collections module, this issue is assigned to his, and he had valid objections to previous version of the patch. Even one of this reason is enough to wait his review before committing. Thank you Raymond.
msg251778 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-28 17:12
Ping.
msg251831 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-29 09:41
UserDict_self_and_dict_keywords_3.patch looks good to me.
msg251886 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-29 20:54
New changeset 4c5407e1b0ec by Serhiy Storchaka in branch '2.7': Issue #22609: Constructor and the update method of collections.UserDict now https://hg.python.org/cpython/rev/4c5407e1b0ec New changeset 1869f5625392 by Serhiy Storchaka in branch '3.4': Issue #22609: Constructor of collections.UserDict now accepts the self keyword https://hg.python.org/cpython/rev/1869f5625392 New changeset ab7e3f1f9f88 by Serhiy Storchaka in branch '3.5': Issue #22609: Constructor of collections.UserDict now accepts the self keyword https://hg.python.org/cpython/rev/ab7e3f1f9f88 New changeset 901964295066 by Serhiy Storchaka in branch 'default': Issue #22609: Constructor of collections.UserDict now accepts the self keyword https://hg.python.org/cpython/rev/901964295066
msg251888 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-09-29 20:59
Thank you all for your reviews.
History
Date User Action Args
2022-04-11 14:58:09 admin set github: 66799
2015-09-29 20:59:53 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2015-09-29 20:54:28 python-dev set messages: +
2015-09-29 09:41:01 vstinner set nosy: + vstinnermessages: +
2015-09-28 17:12:54 serhiy.storchaka set messages: +
2015-07-21 07:02:52 ethan.furman set nosy: - ethan.furman
2015-07-20 05:11:18 serhiy.storchaka set messages: +
2015-07-20 04:46:33 rhettinger set messages: +
2015-07-20 04:20:01 martin.panter set messages: +
2015-07-19 10:16:54 serhiy.storchaka set messages: +
2015-06-29 15:35:13 martin.panter set messages: + stage: patch review -> commit review
2015-06-27 02:49:34 yselivanov set nosy: + yselivanovmessages: +
2015-06-26 17:59:00 serhiy.storchaka set files: + UserDict_self_and_dict_keywords_3.patchmessages: + versions: + Python 3.6
2015-05-31 00:20:34 martin.panter set nosy: + martin.pantermessages: +
2015-05-30 16:17:19 serhiy.storchaka set messages: +
2015-05-16 16:11:32 serhiy.storchaka set messages: +
2015-05-16 16:11:09 serhiy.storchaka link issue22958 dependencies
2015-03-31 05:28:50 serhiy.storchaka set files: + UserDict_self_and_dict_keywords_2.patchmessages: +
2015-03-31 02:19:03 berker.peksag set nosy: + berker.peksagmessages: +
2015-03-25 18:46:52 serhiy.storchaka set files: + UserDict_self_and_dict_keywords.patchmessages: +
2015-01-28 09:02:09 serhiy.storchaka set messages: +
2014-12-09 08:38:52 rhettinger set messages: +
2014-12-01 17:08:35 rhettinger set priority: high -> normalassignee: serhiy.storchaka -> rhettinger
2014-12-01 12:42:20 ethan.furman set messages: +
2014-12-01 08:58:50 serhiy.storchaka set messages: +
2014-11-27 17:05:38 python-dev set messages: +
2014-11-27 16:00:51 serhiy.storchaka set messages: +
2014-11-27 15:51:03 python-dev set messages: +
2014-11-27 14:54:56 python-dev set nosy: + python-devmessages: +
2014-11-27 06:47:59 rhettinger set assignee: rhettinger -> serhiy.storchakamessages: +
2014-11-01 03:41:42 rhettinger set priority: normal -> high
2014-10-13 16:32:26 larry set nosy: + larrymessages: +
2014-10-13 15:27:46 ethan.furman set messages: +
2014-10-12 18:43:49 ethan.furman set messages: +
2014-10-12 06:57:29 serhiy.storchaka set files: + collections_pos_only_params2.patchmessages: +
2014-10-12 06:15:07 rhettinger set priority: low -> normalmessages: +
2014-10-11 17:10:02 rhettinger set priority: normal -> lowmessages: +
2014-10-11 16:56:07 rhettinger set assignee: rhettinger
2014-10-11 14:12:17 serhiy.storchaka set files: + collections_pos_only_params.patchversions: + Python 2.7, Python 3.5keywords: + patchnosy: + rhettinger, serhiy.storchakamessages: + stage: patch review
2014-10-11 12:26:52 ethan.furman set nosy: + ethan.furman
2014-10-11 12:20:17 mark.dickinson set nosy: + mark.dickinson
2014-10-11 12:04:09 abacabadabacaba create