-
-
Notifications
You must be signed in to change notification settings - Fork 54
Are there any specs for the typed AST? #4
Comments
The difference between At parse time, type comments and type annotations are very different beasts. Type annotations are parsed as expressions because they actually are expressions that are executed at function definition time. (This behavior is already part of the standard Python 3.5 That said, it seems like it might now make sense to parse the type comments as expressions. I'll think about doing that. |
Thanks a lot for the answer! This will do. Next time I should read the docstrings more closely. As a side note, I've published an experimental unparser for your typed-ast, called typed-astunparse: https://github.com/mbdevpl/typed-astunparse - I use it for my research, but if it would have any use otherwise, I'd be very glad :) BTW, since you seem to be on the forefront of Python development, do you happen to know of any discussion about introducing AST unparsing into core? Actually, there has been a hidden Or, question more related to typed-ast project: would typed ast unparser be welcome in this module, if there happens to be a volunteer to write it? It's ok to have ast/astunparse typed-ast/typed-astunparse - it's just that for me these really belong together. Asking just out of curiosity, please answer if you happen to have some free time :) |
I'm curious about the use case for unparsing without preservation of non-type comments. How common is this need? Wouldn't you be better off saving the original source code? |
I'm doing a kind of source-to-source translation project. The original code (and sometimes target code) is not necessarily Python. I'm experimenting with type hints as a method of increasing performance. |
OK, so the output is not meant for human consumption, right? You're essentially "transpiling" some language to Python so it can be executed. Then the ast unparser makes total sense. |
Fix compilation on MSVC.
I've started experimenting with this project and it works really nice so far, but what I find that is missing is the description of the typed AST. For ordinary AST there is some effort going on here: https://greentreesnakes.readthedocs.io/en/latest/nodes.html . However, is there any kind of documentation with regard to how
typed_ast.ast35
should look?E.g.
type_comment
seems to be treated as just a string. However what is done e.g. in mypy is the type comment is treated as code. Is that intended?Another example is here, where type annotations are not treated as strings, but are parsed normally:
The text was updated successfully, but these errors were encountered: