Message276981
It's inconsistent that defaultdict([]) should be rejected:
>>> defaultdict([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: first argument must be callable or None
but defaultdict.fromkeys([]) is okay:
>>> defaultdict.fromkeys([])
defaultdict(None, {})
The constructor signature differs between defaultdict and dict, and defaultdict.fromkeys is an alternate constructor, so it seems reasonable to also change its signature.
Also confusing is that I can call fromkeys on an instance of defaultdict:
>>> dd = defaultdict(list)
>>> dd.fromkeys([1])
defaultdict(None, {1: None})
Instinctively I expect the default_factory to be carried over, even though I realise that would be odd behaviour for Python. If defaultdict.fromkeys were to expect a mandatory default_factory argument there wouldn't be this moment of confusion. |
|
Date |
User |
Action |
Args |
2016-09-19 15:48:05 | allenap | set | recipients:
+ allenap, rhettinger, SilentGhost, serhiy.storchaka, justanr |
2016-09-19 15:48:05 | allenap | set | messageid: <1474300085.74.0.799078848053.issue23372@psf.upfronthosting.co.za> |
2016-09-19 15:48:05 | allenap | link | issue23372 messages |
2016-09-19 15:48:05 | allenap | create | |
|