-
-
Notifications
You must be signed in to change notification settings - Fork 54
SyntaxError when parsing per-argument type comments with comma on the next line #58
Comments
This syntax is incompatible with PEP 484. See the paragraph here: https://github.com/python/peps/blob/master/pep-0484.txt#L2097 Relevant quote:
(Emphasis mine) You may also want to see the discussion in the PR you referenced here: #5 (comment) |
Great question! The short answer is: no plans currently. Here's why: First, the major point of departure of typed_ast from ast is that it considers type comments part of the language (which in some senses they are, as specified by PEP 484). As part of this, it considers misplaced type comments to be syntax errors. This is partially due to technical limitations, and I'd likely accept a patch which changed them into warnings, provided it didn't require a massive overhaul. Second, as @ethanhs mentioned above, PEP 484 is specific about the location of the type comments relative to the comma, so per the spec those type comments are not in a valid position. (IIRC that's partly due to beginning-of-the-line commas being considered unpythonic). It could be valuable for typed_ast to be more flexible here, but I'm not sure it's worth the additional complexity. The combination of those two factors results in the behavior that you see. Neither of these things has planned development. I've looked at the referenced issue, but could you talk a bit more about why you want this? Maybe a workaround can be found instead. |
Also, I've always despised the style where the comma comes at the start of the next line. It violates esthetics and good sense. |
The code sample above is an example of what my unparser generates. Implementing unparsing in that way was... very simple. And I was surprised that |
Decompress rework
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.Are there any plans to support this case?
The built-in
ast
succeeds, which seems to be in conflict with the development philosophy oftyped_ast
.The text was updated successfully, but these errors were encountered: