-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Constructors of weakref mapping classes don't accept "self" and "dict" keyword arguments #67147
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
Comments
Dict-like types in the weakref module (WeakValueDictionary and WeakKeyDictionary) don't allow to specify key-value pair as keyword arguments if key is "self" or "dict". >>> import weakref
>>> class A: pass
...
>>> a = A()
>>> d = weakref.WeakValueDictionary(spam=a)
>>> list(d.items())
[('spam', <__main__.A object at 0xb6f3f88c>)]
>>> weakref.WeakValueDictionary(self=a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got multiple values for argument 'self'
>>> weakref.WeakValueDictionary(dict=a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/weakref.py", line 114, in __init__
self.update(*args, **kw)
File "/home/serhiy/py/cpython/Lib/weakref.py", line 261, in update
dict = type({})(dict)
TypeError: 'A' object is not iterable
>>> d = weakref.WeakValueDictionary()
>>> d.update(spam=a)
>>> list(d.items())
[('spam', <__main__.A object at 0xb6f3f88c>)]
>>> d.update(self=a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: update() got multiple values for argument 'self'
>>> d.update(dict=a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/weakref.py", line 261, in update
dict = type({})(dict)
TypeError: 'A' object is not iterable Related issue for the collections module is bpo-22609. I think weakref mapping classes should be fixed in the same manner. |
Here is a patch similar to patch from bpo-22609 which makes WeakValueDictionary constructor and update accept keyword arguments "self" and "dict". |
lgtm |
New changeset 8274fc521e69 by Serhiy Storchaka in branch '2.7': New changeset 01c79072d671 by Serhiy Storchaka in branch '3.4': New changeset 73b6b88ac28a by Serhiy Storchaka in branch '3.5': New changeset 815bb6a2d69e by Serhiy Storchaka in branch 'default': |
self
keyword argumentNote: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: