Skip to content

[red-knot] Disambiguate display for union types #16893

@dhruvmanila

Description

@dhruvmanila

For example, when using callable types in a union:

from typing import Callable


def foo(x: Callable[[], int] | None):
    # red-knot: Revealed type is `() -> int | None` [revealed-type]
    reveal_type(x)

This can be confused with the return type could be read as int | None.

To disambiguate, we should add parentheses like:

red-knot: Revealed type is `(() -> int) | None` [revealed-type]

This is what Pyright does as well while mypy uses the Union[...] syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedContributions especially welcometyMulti-file analysis & type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions