Accepting multiple mappings as positional arguments to create dicts
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?
participants (9)
-
Andrés Delfino
-
Chris Angelico
-
Daniel Moisset
-
Ed Kellett
-
Guido van Rossum
-
Mike Miller
-
Serhiy Storchaka
-
Steven D'Aprano
-
Sven R. Kunze