8000 mypy cannot parse type comment of "with" and "for" statement in PEP 484 · Issue #892 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content
mypy cannot parse type comment of "with" and "for" statement in PEP 484 #892
Closed
@t2y

Description

@t2y

I tried to check type comments, but it cannot parse "with" and "for" statement as below.

# Example 1
x = []   # type: List[Employee]
x, y, z = [], [], []  # type: List[int], List[int], List[str]
x, y, z = [], [], []  # type: (List[int], List[int], List[str])
x = [
   1,
   2,
]  # type: List[int]

# Example 2
from contextlib import contextmanager

@contextmanager
def frobnicate():
    yield 1

with frobnicate() as foo:  # type: int
    # Here foo is an int
    ...

# Example 3
points = [(1.0, 2.5)]  # type: List[Tuple[float, float]]
for x, y in points:  # type: float, float
    # Here x and y are floats
    ...
$ mypy type_comments.py 
type_comments.py:17: error: Parse error before "
54B5
int"
type_comments.py:23: error: Parse error before "float"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0