This rule raises an issue when dict(), list(), or tuple() are used to create empty collections or to initialize dictionaries with keyword arguments.

Why is this an issue?

Python provides concise literal syntax for creating empty dictionaries ({}), lists ([]), and tuples (()). It also offers a direct literal syntax for initializing dictionaries with key-value pairs (e.g., {'a': 1, 'b': 2}).

Using the function calls dict(), list(), and tuple() for these purposes is generally less preferred for a few reasons:

Specifically, the following patterns are discouraged:

While the functional difference is minimal for creating empty collections or simple dictionaries, adopting literals promotes a more direct and idiomatic coding style.

How to fix it

To fix this replace the function calls dict(), list(), and tuple() with their equivalent literal syntax.

empty_d = dict() # Noncompliant: the dict constructor is used instead of the literal syntax
empty_d = {} # Compliant

Resources

Documentation