[issue30408] [defaultdict] default_factory should accept a "key" default parameter (which can be passed my __missing__)

2017-05-20 Thread Nam
Nam added the comment: Sure, thanks Raymond and Steven for your thoughts. -- stage: -> resolved status: open -> closed ___ Python tracker ___

[issue30408] [defaultdict] default_factory should accept a "key" default parameter (which can be passed my __missing__)

2017-05-19 Thread Steven D'Aprano
Steven D'Aprano added the comment: I think this should be closed. For backwards compatibility, the defaultdict default_factory function must remain as it is. There is lots of code that uses something like `int` or `list` as the factory, and if the missing key was to be passed, the code would

[issue30408] [defaultdict] default_factory should accept a "key" default parameter (which can be passed my __missing__)

2017-05-19 Thread Raymond Hettinger
Raymond Hettinger added the comment: Take a look at the __missing__(key) method for the regular dict API to see if it meets your needs. It is in the ``d[key]`` section at https://docs.python.org/3/library/stdtypes.html#dict >>> class UpperDict(dict): def __missing__(self, key):

[issue30408] [defaultdict] default_factory should accept a "key" default parameter (which can be passed my __missing__)

2017-05-19 Thread Nam
New submission from Nam: currently default_factory does not accept any parameter. This made the default value generated by it constant among keys. If default_factory takes in key as the parameter, it should be able to generate default values based on key, which provide more flexibility to the