Skip to content

"invalid syntax" with type annotation on return statement #8218

Closed
@blueyed

Description

@blueyed

Given t-return.py:

from typing import List


def getfoo():
    return ["foo"]


def foo() -> List[str]:
    return getfoo()  # type: List[str]

mypy --show-column-numbers t-return.py shows:

t-return.py:9:31: error: invalid syntax

Note that the reported column is the "i" in "List", which appears to be off in general.

The workaround is to split the return into an assignment (with the annotation), and then returning the variable. But I think it would be nice if the annotation would work with the return statement already.
If that's not going to be supported, the error should be more descriptive probably.

mypy 0.770+dev.9101707bd0c96624d09cb31fe573d7e25c89a35c.dirty

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions