PEP-584 Add Union Operators To dict ¶
See also
New syntax ¶
d | other
Create a new dictionary with the merged keys and values of d and other, which must both be dictionaries.
The values of other take priority when d and other share keys.
d |= other
Update the dictionary d with keys and values from other, which may be either a mapping or an iterable of key/value pairs.
The values of other take priority when d and other share keys.
New in version 3.9.
Examples ¶
matplotlib/legend.py ¶
Before:
hm = default_handler_map.copy()
hm.update(self._handler_map)
return hm
After:
return default_handler_map | self._handler_map
pygments/lexer.py ¶
Before:
kwargs.update(lexer.options)
lx = lexer.__class__(**kwargs)
After:
lx = lexer.__class__(**(kwargs | lexer.options))