[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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 break.

As Raymond says, if you need the key passed to your factory, you can subclass 
dict and give it a __missing__ method.

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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):
return key.upper()

>>> d = UpperDict()
>>> print(d['tom'])
TOM

--
assignee:  -> rhettinger
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 class defaultdict.

--
components: Extension Modules
messages: 293992
nosy: namtt
priority: normal
severity: normal
status: open
title: [defaultdict] default_factory should accept a "key" default parameter 
(which can be passed my __missing__)
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com