classification
Title: defaultdict miss behave when using default_factory passed as kwargs
Type: behavior Stage: patch review
Components: ctypes, Documentation Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Dennis Sweeney, docs@python, moshemorad12340, ronaldoussoren
Priority: normal Keywords: patch

Created on 2020-08-23 19:04 by moshemorad12340, last changed 2020-08-24 13:49 by Dennis Sweeney.

Pull Requests
URL Status Linked Edit
PR 21945 open Dennis Sweeney, 2020-08-24 13:21
Messages (3)
msg375823 - (view) Author: Moshe Morad (moshemorad12340) Date: 2020-08-23 19:04
How to reproduce
----------------
>>> from collections import defaultdict
>>> dd = defaultdict(default_factory=list)
>>> dd
defaultdict(None, {'default_factory': <class 'list'>})
>>> print(dd.default_factory)
None


Analysis
--------
defdict_init(PyObject *self, PyObject *args, PyObject *kwds) function that initializing defaultdict object ignores the kwds and pass them to the dict init only.


Expect:
-------
Since we can understand why we want to move kwds to dict without modification consider at least adding comment in the docstring or enforce it as positional argument only.
msg375840 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2020-08-24 10:14
This is intentional behaviour, the factory can only be passed as a positional argument.

The documentation[1] mentions this, although its probably possible to write this a bit clearer.

[1] https://docs.python.org/3.8/library/collections.html#collections.defaultdict
msg375843 - (view) Author: Dennis Sweeney (Dennis Sweeney) * Date: 2020-08-24 13:49
PR 21945 changes the signature:

- defaultdict(default_factory[, ...])
+ defaultdict(default_factory=None, /, [...])
History
Date User Action Args
2020-08-24 13:49:20Dennis Sweeneysetmessages: + msg375843
2020-08-24 13:21:46Dennis Sweeneysetkeywords: + patch
nosy: + Dennis Sweeney

pull_requests: + pull_request21055
stage: patch review
2020-08-24 10:14:28ronaldoussorensetnosy: + ronaldoussoren
messages: + msg375840
2020-08-23 19:23:21iritkatrielsetversions: + Python 3.9, Python 3.10
2020-08-23 19:04:06moshemorad12340create