[Python-ideas] Accepting multiple mappings as positional arguments to create dicts

Daniel Moisset dmoisset at machinalis.com
Mon Apr 9 10:09:21 EDT 2018


No worries, already implemented features happens so often in this list that
there's a story about Guido going back in a time machine to implement them
;-)

Just wanted to check that I had understood what you suggested correctly

On 9 April 2018 at 12:42, Andrés Delfino <adelfino at gmail.com> wrote:

> Sorry, I didn't know that kwargs unpacking in dictionaries displays don't
> raise a TypeError exception.
>
> On Mon, Apr 9, 2018 at 8:23 AM, Daniel Moisset <dmoisset at machinalis.com>
> wrote:
>
>> In which way would this be different to {**mapping1, **mapping2,
>> **mapping3} ?
>>
>> On 8 April 2018 at 22:18, Andrés Delfino <adelfino at gmail.com> wrote:
>>
>>> Hi!
>>>
>>> I thought that maybe dict could accept several mappings as positional
>>> arguments, like this:
>>>
>>> class Dict4(dict):
>>>>     def __init__(self, *args, **kwargs):
>>>>         if len(args) > 1:
>>>>             if not all([isinstance(arg, dict) for arg in args]):
>>>>                 raise TypeError('Dict4 expected instances of dict since
>>>> multiple positional arguments were passed')
>>>>
>>>>             temp = args[0].copy()
>>>>
>>>>             for arg in args[1:]:
>>>>                 temp.update(arg)
>>>>
>>>>             super().__init__(temp, **kwargs)
>>>>         else:
>>>>             super().__init__(*args, **kwargs)
>>>>
>>>
>>> AFAIK, this wouldn't create compatibility problems, since you can't pass
>>> two positional arguments now anyways.
>>>
>>> It would be useful to solve the "sum/union dicts" discussion, for
>>> example: requests.get(url, params=dict(params, {'foo': bar})
>>>
>>> Whar are your thoughts?
>>>
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> https://mail.python.org/mailman/listinfo/python-ideas
>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>
>>>
>>
>>
>> --
>> Daniel F. Moisset - UK Country Manager - Machinalis Limited
>> www.machinalis.co.uk <http://www.machinalis.com>
>> Skype: @dmoisset T: + 44 7398 827139
>>
>> 1 Fore St, London, EC2Y 9DT
>> <https://maps.google.com/?q=1+Fore+St,+London,+EC2Y+9DT&entry=gmail&source=g>
>>
>> Machinalis Limited is a company registered in England and Wales.
>> Registered number: 10574987.
>>
>
>


-- 
Daniel F. Moisset - UK Country Manager - Machinalis Limited
www.machinalis.co.uk <http://www.machinalis.com>
Skype: @dmoisset T: + 44 7398 827139

1 Fore St, London, EC2Y 9DT

Machinalis Limited is a company registered in England and Wales. Registered
number: 10574987.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180409/a65b6a35/attachment.html>


More information about the Python-ideas mailing list