This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document collections.defaultdict parameter default_factory
Type: behavior Stage: resolved
Components: ctypes, Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Dennis Sweeney, docs@python, miss-islington, moshemorad12340, ronaldoussoren, terry.reedy
Priority: normal Keywords: patch

Created on 2020-08-23 19:04 by moshemorad12340, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21945 merged Dennis Sweeney, 2020-08-24 13:21
PR 26850 merged miss-islington, 2021-06-22 14:19
PR 26851 merged miss-islington, 2021-06-22 14:19
Messages (6)
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) * (Python committer) Date: 2020-08-24 13:49
PR 21945 changes the signature:

- defaultdict(default_factory[, ...])
+ defaultdict(default_factory=None, /, [...])
msg396340 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-22 14:19
New changeset d1ae57027fc39ff60dcfc1b63881400e5ca3ce56 by Dennis Sweeney in branch 'main':
bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
https://github.com/python/cpython/commit/d1ae57027fc39ff60dcfc1b63881400e5ca3ce56
msg396343 - (view) Author: miss-islington (miss-islington) Date: 2021-06-22 14:42
New changeset a65df3f9fc9a51f3e8d710492aafe07b13f0be0f by Miss Islington (bot) in branch '3.9':
bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
https://github.com/python/cpython/commit/a65df3f9fc9a51f3e8d710492aafe07b13f0be0f
msg396426 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-23 14:58
New changeset 88a3342314c8b9ff40a2b6fd4759cfbf64712c67 by Miss Islington (bot) in branch '3.10':
bpo-41621: Document defaultdict's default_factory parameter (GH-21945)
https://github.com/python/cpython/commit/88a3342314c8b9ff40a2b6fd4759cfbf64712c67
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85787
2021-06-23 14:59:34terry.reedysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-06-23 14:58:40terry.reedysetmessages: + msg396426
2021-06-22 14:42:49miss-islingtonsetmessages: + msg396343
2021-06-22 14:19:40miss-islingtonsetpull_requests: + pull_request25432
2021-06-22 14:19:34miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25431
2021-06-22 14:19:34terry.reedysetnosy: + terry.reedy
messages: + msg396340
2021-06-22 13:16:51terry.reedysettitle: defaultdict miss behave when using default_factory passed as kwargs -> Document collections.defaultdict parameter default_factory
versions: + Python 3.11, - Python 3.8
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