unnecessary-default-type-args / R6007ΒΆ

Message emitted:

Type `%s` has unnecessary default type args. Change it to `%s`.

Description:

Emitted when types have default type args which can be omitted. Mainly used for `typing.Generator` and `typing.AsyncGenerator`.

Problematic code:

from collections.abc import AsyncGenerator, Generator

a1: AsyncGenerator[int, None]  # [unnecessary-default-type-args]
b1: Generator[int, None, None]  # [unnecessary-default-type-args]

Correct code:

from collections.abc import AsyncGenerator, Generator

a1: AsyncGenerator[int]
b1: Generator[int]

Configuration file:

[main]
load-plugins=pylint.extensions.typing

Additional details:

At the moment, this check only works for Generator and AsyncGenerator.

Starting with Python 3.13, the SendType and ReturnType default to None. As such it's no longer necessary to specify them. The collections.abc variants don't validate the number of type arguments. Therefore the defaults for these can be used in earlier versions as well.

Related links:

Note

This message is emitted by the optional 'typing' checker, which requires the pylint.extensions.typing plugin to be loaded.

Created by the typing checker.