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.

Author Steele Farnsworth
Recipients Steele Farnsworth
Date 2020-04-10.21:19:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586553586.38.0.834422539726.issue40248@roundup.psfhosted.org>
In-reply-to
Content
I have implemented a class in the C code of the collections module which has similar behavior to the defaultdict class. This class, dynamicdict, supplies values for keys that have not yet been added using a default factory callable, but unlike defaultdict, the missing key itself is passed to the callable. This code can be seen here: https://github.com/swfarnsworth/cpython/blob/3.8/Modules/_collectionsmodule.c#L2234

While this does introduce a lot of redundant code, I'm not sure how it could be done without copying the implementation of the defaultdict class and adjusting how the default factory is called. For example, I don't believe that it's possible to support both behaviors within the defaultdict class without breaking backwards compatibility or adding another parameter to the constructor for the defaultdict class.

I would be happy to further explain the concept, implementation, potential use cases, or anything else that might work towards the adoption of this feature.
History
Date User Action Args
2020-04-10 21:19:46Steele Farnsworthsetrecipients: + Steele Farnsworth
2020-04-10 21:19:46Steele Farnsworthsetmessageid: <1586553586.38.0.834422539726.issue40248@roundup.psfhosted.org>
2020-04-10 21:19:46Steele Farnsworthlinkissue40248 messages
2020-04-10 21:19:46Steele Farnsworthcreate