Skip to content

Remove Redundant Constructor in Dict Union

Sourcery refactoring id: remove-redundant-constructor-in-dict-union

Description

Before

x = dict(y) | z

After

x = y | z

Explanation

The Python dictionary union operator returns a new dictionary, without modifying any of its operands. As a result, dictionary copies or reconstructions are unnecessary, and clutter the code.

See also: unwrap-iterable-construction, dict-assign-update-to-union