Skip to content

Remove Redundant Constructor in Dict Union

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

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

Section titled “Sourcery refactoring id: remove-redundant-constructor-in-dict-union”
x = dict(y) | z
x = y | z

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