[2.7, 3.5] Support the per-argument function comment syntax#5
[2.7, 3.5] Support the per-argument function comment syntax#5
Conversation
Adds a type_comments list of strings to the arguments object containing the per-argument type comments of a function, if any.
Puts per-argument type comments into the annotation slot of the argument as a string expression.
|
@gnprice take a look when you have time! |
|
Looking now! Eager to see this in. :-) |
typed_ast/ast35.py
Outdated
| a `type_ignores` field which contains a list of lines which have been | ||
| `# type: ignored`. | ||
| type comment. Per-argument function comments are put into the annotation | ||
| field of each argument. `parse` has been augmented so it can parse |
There was a problem hiding this comment.
This paragraph is probably best turned into bullets at this point -- the four sentences are fairly independent of each other, and the transition from "per-argument function comments" to "parse has been augmented" is particularly abrupt.
|
Done reading. Looks good! I have a number of comments above, but I think they are all small, and I think the only one that affects the behavior is about a syntax-error case. |
Python 2 per-argument type comments are now converted into Python 3 annotations.
|
|
||
| args = [convert_arg(arg) for arg in n.args] | ||
| def get_type_comment(i): | ||
| if i < len(n.type_comments): |
There was a problem hiding this comment.
Huh, will this work if there are no type comments -- do we end up with an empty sequence for n.type_comments, or None?
There was a problem hiding this comment.
It's an empty sequence.
|
Done reading the new commit too. |
582aa47 to
314d17d
Compare
|
Pushed new commit with feedback. |
typed_ast/ast35.py
Outdated
| - `parse` has been augmented so it can parse function signature types when | ||
| called with `mode=func_type`. | ||
| - `Module` has a `type_ignores` field which contains a list of | ||
| lines which have been `# type: ignored`. |
There was a problem hiding this comment.
Hmm, it looks like the "d" is on the wrong side of these backticks. A pre-existing nit.
There was a problem hiding this comment.
Ooh, let me fix that.
|
Finished reading through the new version -- just a couple of comments which are all on documentation. (I wish I knew a reasonable way to get GitHub to tell me what the recent comments were.) |
ast27/Parser/Python.asdl
Outdated
| -- type_comments is used to support the per-argument type comment syntax. | ||
| -- It is either an empty list or a list with length equal to the number of | ||
| -- args (including varargs and kwargs, if present) and with members set to the | ||
| -- string of each arg's type comment, if present, or None otherwise. |
There was a problem hiding this comment.
Is this aligned funny, or is GitHub displaying it in a surprising way?
There was a problem hiding this comment.
The file uses tabs. Fixed
|
Thanks for the detailed review! |
For Python 2.7:
Adds a type_comments list of strings to the arguments object containing
the per-argument type comments of a function, if any.
For Python 3.5:
Puts per-argument type comments into the annotation slot of the
argument as a string expression.
This change contains some autogenerated files:
Python/graminit.cis autogenerated fromGrammar/GrammarInclude/Python-ast.handPython/Python-ast.care autogenerated fromParser/Python.asdl