Author serhiy.storchaka
Recipients fdrake, pitrou, rhettinger, serhiy.storchaka
Date 2014-11-27.16:13:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417104803.61.0.896440563309.issue22958@psf.upfronthosting.co.za>
In-reply-to
Content
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 issue22609. I think weakref mapping classes should be fixed in the same manner.
History
Date User Action Args
2014-11-27 16:13:23serhiy.storchakasetrecipients: + serhiy.storchaka, fdrake, rhettinger, pitrou
2014-11-27 16:13:23serhiy.storchakasetmessageid: <1417104803.61.0.896440563309.issue22958@psf.upfronthosting.co.za>
2014-11-27 16:13:23serhiy.storchakalinkissue22958 messages
2014-11-27 16:13:23serhiy.storchakacreate