Skip to content

unnecessary-default-type-args (UP043)

Derived from the pyupgrade linter.

Fix is always available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for unnecessary default type arguments.

Why is this bad?

Python 3.13 introduced the ability for type parameters to specify default values. As such, the default type arguments for some types in the standard library (e.g., Generator, AsyncGenerator) are now optional.

Omitting type parameters that match the default values can make the code more concise and easier to read.

Examples

from collections.abc import Generator, AsyncGenerator


def sync_gen() -> Generator[int, None, None]:
    yield 42


async def async_gen() -> AsyncGenerator[int, None]:
    yield 42

Use instead:

from collections.abc import Generator, AsyncGenerator


def sync_gen() -> Generator[int]:
    yield 42


async def async_gen() -> AsyncGenerator[int]:
    yield 42

References