Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

SyntaxError when parsing per-argument type comments with comma on the next line #58

@mbdevpl

Description

@mbdevpl

In the PR adding per-argument type comment support #5 there is an unhandled case when comma for an argument is after the type comment, therefore the current version of typed_ast errors out on the following.

In [1]: import inspect

In [2]: import typed_ast.ast3

In [3]: def lovely(spam  # type: bool
   ...:         , eggs  # type: int
   ...:         , ham  # type: str
   ...:         ):
   ...:     # type: (...) -> bool
   ...:     return spam
   ...: 

In [4]: typed_ast.ast3.parse(inspect.getsource(lovely))
  File "<unknown>", line 2
    , eggs  # type: int
    ^
SyntaxError: invalid syntax

Are there any plans to support this case?

In [5]: import ast

In [6]: ast.parse(inspect.getsource(lovely))
Out[6]: <_ast.Module at 0x7fb9584b84e0>

The built-in ast succeeds, which seems to be in conflict with the development philosophy of typed_ast.

This project is a drop-in replacement for the builtin ast module. It is intended to be bug-for-bug compatible and behave identically, except for the presence of a few additional fields on the returned classes and a few additional optional arguments to the parse call.

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