{"action":"created","issue":{"url":"https://api.github.com/repos/dropbox/typed_ast/issues/4","repository_url":"https://api.github.com/repos/dropbox/typed_ast","labels_url":"https://api.github.com/repos/dropbox/typed_ast/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/dropbox/typed_ast/issues/4/comments","events_url":"https://api.github.com/repos/dropbox/typed_ast/issues/4/events","html_url":"https://github.com/dropbox/typed_ast/issues/4","id":160411140,"number":4,"title":"Are there any specs for the typed AST?","user":{"login":"mbdevpl","id":1270332,"avatar_url":"https://avatars.githubusercontent.com/u/1270332?v=3","gravatar_id":"","url":"https://api.github.com/users/mbdevpl","html_url":"https://github.com/mbdevpl","followers_url":"https://api.github.com/users/mbdevpl/followers","following_url":"https://api.github.com/users/mbdevpl/following{/other_user}","gists_url":"https://api.github.com/users/mbdevpl/gists{/gist_id}","starred_url":"https://api.github.com/users/mbdevpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbdevpl/subscriptions","organizations_url":"https://api.github.com/users/mbdevpl/orgs","repos_url":"https://api.github.com/users/mbdevpl/repos","events_url":"https://api.github.com/users/mbdevpl/events{/privacy}","received_events_url":"https://api.github.com/users/mbdevpl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-15T12:34:58Z","updated_at":"2016-06-16T18:36:07Z","closed_at":null,"body":"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?\r\n\r\nE.g. `type_comment` seems to be treated as just a string. However what is done e.g. in [mypy](https://github.com/python/mypy) is the type comment is treated as code. Is that intended?\r\n\r\n```\r\nmy_string = None # type: typing.Optional[str]\r\n```\r\n\r\n```\r\nModule(\r\n  body=[Assign(\r\n    targets=[Name(\r\n      id='my_string',\r\n      ctx=Store())],\r\n    value=NameConstant(value=None),\r\n    type_comment='typing.Optional[str]')],\r\n  type_ignores=[])\r\n```\r\n\r\nAnother example is here, where type annotations are not treated as strings, but are parsed normally:\r\n```\r\ndef function(a: int, b: int) -> int:\r\n    return a + b\r\n```\r\n\r\n```\r\nModule(\r\n  body=[FunctionDef(\r\n    name='function',\r\n    args=arguments(\r\n      args=[\r\n        arg(\r\n          arg='a',\r\n          annotation=Name(\r\n            id='int',\r\n            ctx=Load())),\r\n        arg(\r\n          arg='b',\r\n          annotation=Name(\r\n            id='int',\r\n            ctx=Load()))],\r\n      vararg=None,\r\n      kwonlyargs=[],\r\n      kw_defaults=[],\r\n      kwarg=None,\r\n      defaults=[]),\r\n    body=[Return(value=BinOp(\r\n      left=Name(\r\n        id='a',\r\n        ctx=Load()),\r\n      op=Add(),\r\n      right=Name(\r\n        id='b',\r\n        ctx=Load())))],\r\n    decorator_list=[],\r\n    returns=Name(\r\n      id='int',\r\n      ctx=Load()),\r\n    type_comment=None)],\r\n  type_ignores=[])\r\n```"},"comment":{"url":"https://api.github.com/repos/dropbox/typed_ast/issues/comments/226574275","html_url":"https://github.com/dropbox/typed_ast/issues/4#issuecomment-226574275","issue_url":"https://api.github.com/repos/dropbox/typed_ast/issues/4","id":226574275,"user":{"login":"ddfisher","id":245905,"avatar_url":"https://avatars.githubusercontent.com/u/245905?v=3","gravatar_id":"","url":"https://api.github.com/users/ddfisher","html_url":"https://github.com/ddfisher","followers_url":"https://api.github.com/users/ddfisher/followers","following_url":"https://api.github.com/users/ddfisher/following{/other_user}","gists_url":"https://api.github.com/users/ddfisher/gists{/gist_id}","starred_url":"https://api.github.com/users/ddfisher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddfisher/subscriptions","organizations_url":"https://api.github.com/users/ddfisher/orgs","repos_url":"https://api.github.com/users/ddfisher/repos","events_url":"https://api.github.com/users/ddfisher/events{/privacy}","received_events_url":"https://api.github.com/users/ddfisher/received_events","type":"User","site_admin":false},"created_at":"2016-06-16T18:36:07Z","updated_at":"2016-06-16T18:36:07Z","body":"The difference between `ast35` and Python 3.5's `ast` module are documented briefly in [the module docstring](https://github.com/dropbox/typed_ast/blob/master/typed_ast/ast35.py#L13).\r\n\r\nAt 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 `ast` module and is unchanged in `ast35`.)  Type comments are always returned as strings in the initial parse, but mypy calls back into the parser (with `mode='eval'`) to parse them as expressions.\r\n\r\nThat said, it seems like it might now make sense to parse the type comments as expressions.  I'll think about doing that."}}
{"actor":{"display_login":"ddfisher"}}