[issue41621] defaultdict miss behave when using default_factory passed as kwargs

New submission from Moshe Morad <moshemorad12340@gmail.com>: 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. ---------- assignee: docs@python components: Documentation, ctypes messages: 375823 nosy: docs@python, moshemorad12340 priority: normal severity: normal status: open title: defaultdict miss behave when using default_factory passed as kwargs type: behavior versions: Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41621> _______________________________________

Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- versions: +Python 3.10, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41621> _______________________________________

Ronald Oussoren <ronaldoussoren@mac.com> added the comment: 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 ---------- nosy: +ronaldoussoren _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41621> _______________________________________

Change by Dennis Sweeney <sweeney.dennis650@gmail.com>: ---------- keywords: +patch nosy: +Dennis Sweeney nosy_count: 3.0 -> 4.0 pull_requests: +21055 stage: -> patch review pull_request: https://github.com/python/cpython/pull/21945 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41621> _______________________________________

Dennis Sweeney <sweeney.dennis650@gmail.com> added the comment: PR 21945 changes the signature: - defaultdict(default_factory[, ...]) + defaultdict(default_factory=None, /, [...]) ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue41621> _______________________________________
participants (4)
-
Dennis Sweeney
-
Irit Katriel
-
Moshe Morad
-
Ronald Oussoren