Skip to content

Multiline syntax that is normally invalid is accepted inside stringized annotations. #6940

@elenakrittik

Description

@elenakrittik

Describe the bug
Multiline syntax that is normally invalid is accepted inside stringized annotations.

Code or Screenshots
If possible, provide a minimal, self-contained code sample (surrounded by triple back ticks) to demonstrate the issue. The code should define or import all referenced symbols.

from typing_extensions import TypeAlias


Alias1 = (
    int
    | str
    | bool
)  # parentheses required

Alias2: TypeAlias = """
    int
    | str
    | bool
"""  # mypy: Invalid type comment or annotation  [valid-type]
     # ruff (a linter): [F722] Syntax error in forward annotation
     # pyright: 0 errors, 0 warnings, 0 informations

VS Code extension or command-line
Command line, 1.1.345

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions