[issue30040] new empty dict can be more small

Terry J. Reedy report at bugs.python.org
Tue Mar 12 18:02:27 EDT 2019


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Some of my thoughts on this.

Conceptually, I expected that clearing a normal dict should make it an empty normal dict.  I presume that making it instead an empty shared key dict is a matter of efficiency and code simplicity.  If the 'anomaly' is to be corrected, changing .clear would be an alternative.

The fact that this patch 'rescues' people who use .setdefault when collections.defaultdict would be better does not especially persuade me (msg291817).  The dict method doc and docstring could refer to defaultdict for such situations.

In 3.8.0a2, empty sets, like empty dicts, are ready to add. Empty lists in a2 are *not*, so pre-allocation is not universal in CPython for mutable collections.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue30040>
_______________________________________


More information about the Python-bugs-list mailing list