Skip to content

UP007 should leave type aliases alone #2981

@aberres

Description

@aberres

Given the following snippet, ruff should not throw an error. At least this is the behavior of pyupgrade.

There are cases where one still needs an explicit Optional. See fastapi/typer#348 / fastapi/typer#348 (comment) for an example.

Code

from __future__ import annotations

from typing import Optional

StrOrNone = Optional[str]

Output

up007.py:6:13: UP007 [*] Use `X | Y` for type annotations
Found 1 error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions