Skip to content

Commit 3f1daea

Browse files
committed
Clarify defaultdict keyword argument behavior in docs
1 parent f141e8e commit 3f1daea

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Doc/library/collections.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
727727
as if they were passed to the :class:`dict` constructor, including keyword
728728
arguments.
729729

730+
Note that this means ``defaultdict(default_factory=list)`` (for example),
731+
will create a dict with a key of ``'default_factory'`` and a value of
732+
:class:`list`. Instead, call ``defaultdict(list)``.
733+
730734

731735
:class:`defaultdict` objects support the following method in addition to the
732736
standard :class:`dict` operations:

Modules/_collectionsmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,10 @@ a new value when a key is not present, in __getitem__ only.\n\
24762476
A defaultdict compares equal to a dict with the same items.\n\
24772477
All remaining arguments are treated the same as if they were\n\
24782478
passed to the dict constructor, including keyword arguments.\n\
2479+
\n\
2480+
Note that this means defaultdict(default_factory=list) (for\n\
2481+
example), will create a dict with a key of 'default_factory'\n\
2482+
and a value of <class 'list'>. Instead, call defaultdict(list).\n\
24792483
");
24802484

24812485
/* See comment in xxsubtype.c */

0 commit comments

Comments
 (0)