{"action":"created","comment":{"url":"https://api.github.com/repos/python/mypy/pulls/comments/54284635","id":54284635,"diff_hunk":"@@ -0,0 +1,744 @@\n+from functools import wraps\n+import sys\n+\n+from typing import Tuple, Union, TypeVar, Callable, Sequence\n+from mypy.nodes import (\n+    MypyFile, Import, ImportAll, ImportFrom, FuncDef, OverloadedFuncDef,\n+    ClassDef, Decorator, Block, Var, OperatorAssignmentStmt,\n+    ExpressionStmt, AssignmentStmt, ReturnStmt, RaiseStmt, AssertStmt,\n+    DelStmt, BreakStmt, ContinueStmt, PassStmt, GlobalDecl,\n+    WhileStmt, ForStmt, IfStmt, TryStmt, WithStmt,\n+    TupleExpr, GeneratorExpr, ListComprehension, ListExpr, ConditionalExpr,\n+    DictExpr, SetExpr, NameExpr, IntExpr, StrExpr, BytesExpr,\n+    FloatExpr, CallExpr, SuperExpr, MemberExpr, IndexExpr, SliceExpr, OpExpr,\n+    UnaryExpr, FuncExpr, ComparisonExpr,\n+    StarExpr, YieldFromExpr, NonlocalDecl, DictionaryComprehension,\n+    SetComprehension, ComplexExpr, EllipsisExpr, YieldExpr, Argument,\n+    ARG_POS, ARG_OPT, ARG_STAR, ARG_NAMED, ARG_STAR2\n+)\n+from mypy.types import Type, CallableType, AnyType, UnboundType, TupleType, TypeList, EllipsisType\n+from mypy import defaults\n+from mypy.errors import Errors\n+\n+try:\n+    import typed_ast  # type: ignore\n+except ImportError:\n+    print('You must install the typed_ast module before you can run mypy with `--fast-parser`.\\n'\n+          'The typed_ast module can be found at https://github.com/ddfisher/typed_ast',\n+          file=sys.stderr)\n+    sys.exit(1)\n+\n+T = TypeVar('T')\n+\n+\n+def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,\n+          pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,\n+          custom_typing_module: str = None, implicit_any: bool = False) -> MypyFile:\n+    \"\"\"Parse a source file, without doing any semantic analysis.\n+\n+    Return the parse tree. If errors is not provided, raise ParseError\n+    on failure. Otherwise, use the errors object to report parse errors.\n+\n+    The pyversion (major, minor) argument determines the Python syntax variant.\n+    \"\"\"\n+    is_stub_file = bool(fnam) and fnam.endswith('.pyi')\n+    try:\n+        ast = typed_ast.parse(source, fnam, 'exec')\n+    except SyntaxError as e:\n+        if errors:\n+            errors.set_file('<input>' if fnam is None else fnam)\n+            errors.report(e.lineno, e.msg)  # type: ignore\n+        else:\n+            raise\n+    else:\n+        tree = ASTConverter().visit(ast)\n+        tree.path = fnam\n+        tree.is_stub = is_stub_file\n+        return tree\n+\n+    return MypyFile([],\n+                    [],\n+                    False,\n+                    set(),\n+                    weak_opts=set())\n+\n+\n+def parse_type_comment(type_comment: str, line: int) -> Type:\n+    typ = typed_ast.parse(type_comment, '<type_comment>', 'eval')\n+    return TypeConverter(line=line).visit(typ.body)\n+\n+\n+def with_line(f):\n+    @wraps(f)\n+    def wrapper(self, ast):\n+        node = f(self, ast)\n+        node.set_line(ast.lineno)\n+        return node\n+    return wrapper\n+\n+\n+def find(f: Callable[[T], bool], seq: Sequence[T]) -> T:\n+    for item in seq:\n+        if f(item):\n+            return item\n+    return None\n+\n+\n+class ASTConverter(typed_ast.NodeTransformer):\n+    def __init__(self):\n+        self.in_class = False\n+        self.imports = []\n+\n+    def generic_visit(self, node):\n+        raise RuntimeError('AST node not implemented: ' + str(type(node)))\n+\n+    def visit_NoneType(self, n):\n+        return None\n+\n+    def visit_list(self, l):\n+        return [self.visit(e) for e in l]\n+\n+    def from_operator(self, op):\n+        if isinstance(op, typed_ast.Add):\n+            return '+'","path":"mypy/fastparse.py","position":103,"original_position":103,"commit_id":"583c072af12f860f1a670cb8d42f7f9fcf2bae22","original_commit_id":"583c072af12f860f1a670cb8d42f7f9fcf2bae22","user":{"login":"gvanrossum","id":2894642,"avatar_url":"https://avatars.githubusercontent.com/u/2894642?v=3","gravatar_id":"","url":"https://api.github.com/users/gvanrossum","html_url":"https://github.com/gvanrossum","followers_url":"https://api.github.com/users/gvanrossum/followers","following_url":"https://api.github.com/users/gvanrossum/following{/other_user}","gists_url":"https://api.github.com/users/gvanrossum/gists{/gist_id}","starred_url":"https://api.github.com/users/gvanrossum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvanrossum/subscriptions","organizations_url":"https://api.github.com/users/gvanrossum/orgs","repos_url":"https://api.github.com/users/gvanrossum/repos","events_url":"https://api.github.com/users/gvanrossum/events{/privacy}","received_events_url":"https://api.github.com/users/gvanrossum/received_events","type":"User","site_admin":false},"body":"Could this be done faster and more compactly using a dict keyed by th various typed_ast classes?","created_at":"2016-02-26T18:51:13Z","updated_at":"2016-02-26T18:51:13Z","html_url":"https://github.com/python/mypy/pull/1218#discussion_r54284635","pull_request_url":"https://api.github.com/repos/python/mypy/pulls/1218","_links":{"self":{"href":"https://api.github.com/repos/python/mypy/pulls/comments/54284635"},"html":{"href":"https://github.com/python/mypy/pull/1218#discussion_r54284635"},"pull_request":{"href":"https://api.github.com/repos/python/mypy/pulls/1218"}}},"pull_request":{"url":"https://api.github.com/repos/python/mypy/pulls/1218","id":59889457,"html_url":"https://github.com/python/mypy/pull/1218","diff_url":"https://github.com/python/mypy/pull/1218.diff","patch_url":"https://github.com/python/mypy/pull/1218.patch","issue_url":"https://api.github.com/repos/python/mypy/issues/1218","number":1218,"state":"open","locked":false,"title":"Add typed_ast fast parser to mypy","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},"body":"To use the new fast parser, you install [typed_ast](https://github.com/ddfisher/typed_ast) and make [these changes](https://github.com/ddfisher/typeshed/commit/48b3b260d1daf2c674f325110c30bcdf7ac483f3) to your local typeshed, then run mypy with `--fast-parser`.  Keep in mind that it currently only works on Python 3 code.\r\n\r\nThis is not yet ready to be merged, as the typeshed being discussed [here](https://github.com/python/typeshed/issues/83) need to be resolved first.","created_at":"2016-02-19T00:58:32Z","updated_at":"2016-02-26T18:51:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"481d6e55972688e87bd693b6e457326cd8932a66","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/python/mypy/pulls/1218/commits","review_comments_url":"https://api.github.com/repos/python/mypy/pulls/1218/comments","review_comment_url":"https://api.github.com/repos/python/mypy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/python/mypy/issues/1218/comments","statuses_url":"https://api.github.com/repos/python/mypy/statuses/583c072af12f860f1a670cb8d42f7f9fcf2bae22","head":{"label":"ddfisher:fast_parser","ref":"fast_parser","sha":"583c072af12f860f1a670cb8d42f7f9fcf2bae22","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},"repo":{"id":49612095,"name":"mypy","full_name":"ddfisher/mypy","owner":{"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},"private":false,"html_url":"https://github.com/ddfisher/mypy","description":"Optional static typing for Python","fork":true,"url":"https://api.github.com/repos/ddfisher/mypy","forks_url":"https://api.github.com/repos/ddfisher/mypy/forks","keys_url":"https://api.github.com/repos/ddfisher/mypy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ddfisher/mypy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ddfisher/mypy/teams","hooks_url":"https://api.github.com/repos/ddfisher/mypy/hooks","issue_events_url":"https://api.github.com/repos/ddfisher/mypy/issues/events{/number}","events_url":"https://api.github.com/repos/ddfisher/mypy/events","assignees_url":"https://api.github.com/repos/ddfisher/mypy/assignees{/user}","branches_url":"https://api.github.com/repos/ddfisher/mypy/branches{/branch}","tags_url":"https://api.github.com/repos/ddfisher/mypy/tags","blobs_url":"https://api.github.com/repos/ddfisher/mypy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ddfisher/mypy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ddfisher/mypy/git/refs{/sha}","trees_url":"https://api.github.com/repos/ddfisher/mypy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ddfisher/mypy/statuses/{sha}","languages_url":"https://api.github.com/repos/ddfisher/mypy/languages","stargazers_url":"https://api.github.com/repos/ddfisher/mypy/stargazers","contributors_url":"https://api.github.com/repos/ddfisher/mypy/contributors","subscribers_url":"https://api.github.com/repos/ddfisher/mypy/subscribers","subscription_url":"https://api.github.com/repos/ddfisher/mypy/subscription","commits_url":"https://api.github.com/repos/ddfisher/mypy/commits{/sha}","git_commits_url":"https://api.github.com/repos/ddfisher/mypy/git/commits{/sha}","comments_url":"https://api.github.com/repos/ddfisher/mypy/comments{/number}","issue_comment_url":"https://api.github.com/repos/ddfisher/mypy/issues/comments{/number}","contents_url":"https://api.github.com/repos/ddfisher/mypy/contents/{+path}","compare_url":"https://api.github.com/repos/ddfisher/mypy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ddfisher/mypy/merges","archive_url":"https://api.github.com/repos/ddfisher/mypy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ddfisher/mypy/downloads","issues_url":"https://api.github.com/repos/ddfisher/mypy/issues{/number}","pulls_url":"https://api.github.com/repos/ddfisher/mypy/pulls{/number}","milestones_url":"https://api.github.com/repos/ddfisher/mypy/milestones{/number}","notifications_url":"https://api.github.com/repos/ddfisher/mypy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ddfisher/mypy/labels{/name}","releases_url":"https://api.github.com/repos/ddfisher/mypy/releases{/id}","deployments_url":"https://api.github.com/repos/ddfisher/mypy/deployments","created_at":"2016-01-14T00:46:40Z","updated_at":"2016-01-14T00:46:42Z","pushed_at":"2016-02-26T01:30:15Z","git_url":"git://github.com/ddfisher/mypy.git","ssh_url":"git@github.com:ddfisher/mypy.git","clone_url":"https://github.com/ddfisher/mypy.git","svn_url":"https://github.com/ddfisher/mypy","homepage":"http://www.mypy-lang.org/","size":13136,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"python:master","ref":"master","sha":"e360daee2ed4352fbb183784f12881cb3c21e384","user":{"login":"python","id":1525981,"avatar_url":"https://avatars.githubusercontent.com/u/1525981?v=3","gravatar_id":"","url":"https://api.github.com/users/python","html_url":"https://github.com/python","followers_url":"https://api.github.com/users/python/followers","following_url":"https://api.github.com/users/python/following{/other_user}","gists_url":"https://api.github.com/users/python/gists{/gist_id}","starred_url":"https://api.github.com/users/python/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/python/subscriptions","organizations_url":"https://api.github.com/users/python/orgs","repos_url":"https://api.github.com/users/python/repos","events_url":"https://api.github.com/users/python/events{/privacy}","received_events_url":"https://api.github.com/users/python/received_events","type":"Organization","site_admin":false},"repo":{"id":7053637,"name":"mypy","full_name":"python/mypy","owner":{"login":"python","id":1525981,"avatar_url":"https://avatars.githubusercontent.com/u/1525981?v=3","gravatar_id":"","url":"https://api.github.com/users/python","html_url":"https://github.com/python","followers_url":"https://api.github.com/users/python/followers","following_url":"https://api.github.com/users/python/following{/other_user}","gists_url":"https://api.github.com/users/python/gists{/gist_id}","starred_url":"https://api.github.com/users/python/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/python/subscriptions","organizations_url":"https://api.github.com/users/python/orgs","repos_url":"https://api.github.com/users/python/repos","events_url":"https://api.github.com/users/python/events{/privacy}","received_events_url":"https://api.github.com/users/python/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/python/mypy","description":"Optional static typing for Python","fork":false,"url":"https://api.github.com/repos/python/mypy","forks_url":"https://api.github.com/repos/python/mypy/forks","keys_url":"https://api.github.com/repos/python/mypy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/python/mypy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/python/mypy/teams","hooks_url":"https://api.github.com/repos/python/mypy/hooks","issue_events_url":"https://api.github.com/repos/python/mypy/issues/events{/number}","events_url":"https://api.github.com/repos/python/mypy/events","assignees_url":"https://api.github.com/repos/python/mypy/assignees{/user}","branches_url":"https://api.github.com/repos/python/mypy/branches{/branch}","tags_url":"https://api.github.com/repos/python/mypy/tags","blobs_url":"https://api.github.com/repos/python/mypy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/python/mypy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/python/mypy/git/refs{/sha}","trees_url":"https://api.github.com/repos/python/mypy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/python/mypy/statuses/{sha}","languages_url":"https://api.github.com/repos/python/mypy/languages","stargazers_url":"https://api.github.com/repos/python/mypy/stargazers","contributors_url":"https://api.github.com/repos/python/mypy/contributors","subscribers_url":"https://api.github.com/repos/python/mypy/subscribers","subscription_url":"https://api.github.com/repos/python/mypy/subscription","commits_url":"https://api.github.com/repos/python/mypy/commits{/sha}","git_commits_url":"https://api.github.com/repos/python/mypy/git/commits{/sha}","comments_url":"https://api.github.com/repos/python/mypy/comments{/number}","issue_comment_url":"https://api.github.com/repos/python/mypy/issues/comments{/number}","contents_url":"https://api.github.com/repos/python/mypy/contents/{+path}","compare_url":"https://api.github.com/repos/python/mypy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/python/mypy/merges","archive_url":"https://api.github.com/repos/python/mypy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/python/mypy/downloads","issues_url":"https://api.github.com/repos/python/mypy/issues{/number}","pulls_url":"https://api.github.com/repos/python/mypy/pulls{/number}","milestones_url":"https://api.github.com/repos/python/mypy/milestones{/number}","notifications_url":"https://api.github.com/repos/python/mypy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/python/mypy/labels{/name}","releases_url":"https://api.github.com/repos/python/mypy/releases{/id}","deployments_url":"https://api.github.com/repos/python/mypy/deployments","created_at":"2012-12-07T13:30:23Z","updated_at":"2016-02-26T14:13:18Z","pushed_at":"2016-02-26T17:12:51Z","git_url":"git://github.com/python/mypy.git","ssh_url":"git@github.com:python/mypy.git","clone_url":"https://github.com/python/mypy.git","svn_url":"https://github.com/python/mypy","homepage":"http://www.mypy-lang.org/","size":13562,"stargazers_count":1103,"watchers_count":1103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":128,"mirror_url":null,"open_issues_count":353,"forks":128,"open_issues":353,"watchers":1103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/python/mypy/pulls/1218"},"html":{"href":"https://github.com/python/mypy/pull/1218"},"issue":{"href":"https://api.github.com/repos/python/mypy/issues/1218"},"comments":{"href":"https://api.github.com/repos/python/mypy/issues/1218/comments"},"review_comments":{"href":"https://api.github.com/repos/python/mypy/pulls/1218/comments"},"review_comment":{"href":"https://api.github.com/repos/python/mypy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/python/mypy/pulls/1218/commits"},"statuses":{"href":"https://api.github.com/repos/python/mypy/statuses/583c072af12f860f1a670cb8d42f7f9fcf2bae22"}}}}