{"action":"created","comment":{"url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/comments/244637591","pull_request_review_id":188556895,"id":244637591,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0NDYzNzU5MQ==","diff_hunk":"@@ -518,6 +527,60 @@ def is_typing_overload_decorator(node):\n     )\n \n \n+def make_tokens(code):\n+    # PY3: tokenize.tokenize requires readline of bytes\n+    if not isinstance(code, bytes):\n+        code = code.encode('UTF-8')\n+    lines = iter(code.splitlines(True))\n+    # next(lines, b'') is to prevent an error in pypy3\n+    return tuple(tokenize_tokenize(lambda: next(lines, b'')))\n+\n+\n+class _TypeableVisitor(ast.NodeVisitor):\n+    \"\"\"Collect the line number and nodes which are deemed typeable by\n+    PEP 484\n+\n+    https://www.python.org/dev/peps/pep-0484/#type-comments\n+    \"\"\"\n+    def __init__(self):\n+        self.typeable_lines = []  # type: int\n+        self.typeable_nodes = {}  # type: Dict[int, ast.AST]\n+\n+    def _typeable(self, node):\n+        # if there is more than one typeable thing on a line last one wins\n+        self.typeable_lines.append(node.lineno)\n+        self.typeable_nodes[node.lineno] = node\n+\n+        self.generic_visit(node)\n+\n+    visit_Assign = visit_For = visit_FunctionDef = visit_With = _typeable\n+    visit_AsyncFor = visit_AsyncFunctionDef = visit_AsyncWith = _typeable\n+\n+\n+def _collect_type_comments(tree, tokens):\n+    visitor = _TypeableVisitor()\n+    visitor.visit(tree)\n+\n+    type_comments = collections.defaultdict(list)\n+    for tp, text, start, _, _ in tokens:\n+        if (\n+                tp != tokenize.COMMENT or  # skip non comments\n+                not text.startswith('# type:') or  # skip non-type comments\n+                text.split()[:3] == ['#', 'type:', 'ignore']  # skip ignores","path":"pyflakes/checker.py","position":73,"original_position":73,"commit_id":"e08d43d4e6ba78a8dd72c04e48b6f3539f0c54ce","original_commit_id":"e08d43d4e6ba78a8dd72c04e48b6f3539f0c54ce","user":{"login":"sigmavirus24","id":240830,"node_id":"MDQ6VXNlcjI0MDgzMA==","avatar_url":"https://avatars3.githubusercontent.com/u/240830?v=4","gravatar_id":"","url":"https://api.github.com/users/sigmavirus24","html_url":"https://github.com/sigmavirus24","followers_url":"https://api.github.com/users/sigmavirus24/followers","following_url":"https://api.github.com/users/sigmavirus24/following{/other_user}","gists_url":"https://api.github.com/users/sigmavirus24/gists{/gist_id}","starred_url":"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sigmavirus24/subscriptions","organizations_url":"https://api.github.com/users/sigmavirus24/orgs","repos_url":"https://api.github.com/users/sigmavirus24/repos","events_url":"https://api.github.com/users/sigmavirus24/events{/privacy}","received_events_url":"https://api.github.com/users/sigmavirus24/received_events","type":"User","site_admin":false},"body":"Perhaps another silly question, why are we doing `text.split()[:3]` to check this but not using split above to see if the comment starts with `# type:`?\r\n\r\nMy guess is that the split here is to accommodate multiple spaces so that all of the following work:\r\n\r\n```\r\n# type: ignore\r\n#   type:       ignore\r\n# type:    ignore\r\n#      type: ignore\r\n```\r\n\r\nBut then we're going to bail on those lines anyway because of `not text.startswith('# type:')` so I'd like to understand the decision here. Do we perhaps want to do:\r\n\r\n```py\r\nfor tp, text, start, _, _ in tokens:\r\n    text_pieces = text.split()\r\n    if (\r\n        tp != tokenize.COMMENT or\r\n        not (text_pieces[:2] == ['#', 'type:'] and\r\n             text_pieces[3] == 'ignore')\r\n    ):\r\n        comment\r\n```","created_at":"2019-01-01T13:31:47Z","updated_at":"2019-01-01T13:35:45Z","html_url":"https://github.com/PyCQA/pyflakes/pull/400#discussion_r244637591","pull_request_url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/comments/244637591"},"html":{"href":"https://github.com/PyCQA/pyflakes/pull/400#discussion_r244637591"},"pull_request":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400"}}},"pull_request":{"url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400","id":241619731,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQxNjE5NzMx","html_url":"https://github.com/PyCQA/pyflakes/pull/400","diff_url":"https://github.com/PyCQA/pyflakes/pull/400.diff","patch_url":"https://github.com/PyCQA/pyflakes/pull/400.patch","issue_url":"https://api.github.com/repos/PyCQA/pyflakes/issues/400","number":400,"state":"open","locked":false,"title":"Parse PEP 484 type comments","user":{"login":"asottile","id":1810591,"node_id":"MDQ6VXNlcjE4MTA1OTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1810591?v=4","gravatar_id":"","url":"https://api.github.com/users/asottile","html_url":"https://github.com/asottile","followers_url":"https://api.github.com/users/asottile/followers","following_url":"https://api.github.com/users/asottile/following{/other_user}","gists_url":"https://api.github.com/users/asottile/gists{/gist_id}","starred_url":"https://api.github.com/users/asottile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asottile/subscriptions","organizations_url":"https://api.github.com/users/asottile/orgs","repos_url":"https://api.github.com/users/asottile/repos","events_url":"https://api.github.com/users/asottile/events{/privacy}","received_events_url":"https://api.github.com/users/asottile/received_events","type":"User","site_admin":false},"body":"Resolves #247","created_at":"2019-01-01T06:32:55Z","updated_at":"2019-01-01T13:35:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9155cbb8c530de84e090e5ea4abd344812d3c78c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400/commits","review_comments_url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400/comments","review_comment_url":"https://api.github.com/repos/PyCQA/pyflakes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PyCQA/pyflakes/issues/400/comments","statuses_url":"https://api.github.com/repos/PyCQA/pyflakes/statuses/e08d43d4e6ba78a8dd72c04e48b6f3539f0c54ce","head":{"label":"asottile:type_comments","ref":"type_comments","sha":"e08d43d4e6ba78a8dd72c04e48b6f3539f0c54ce","user":{"login":"asottile","id":1810591,"node_id":"MDQ6VXNlcjE4MTA1OTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1810591?v=4","gravatar_id":"","url":"https://api.github.com/users/asottile","html_url":"https://github.com/asottile","followers_url":"https://api.github.com/users/asottile/followers","following_url":"https://api.github.com/users/asottile/following{/other_user}","gists_url":"https://api.github.com/users/asottile/gists{/gist_id}","starred_url":"https://api.github.com/users/asottile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asottile/subscriptions","organizations_url":"https://api.github.com/users/asottile/orgs","repos_url":"https://api.github.com/users/asottile/repos","events_url":"https://api.github.com/users/asottile/events{/privacy}","received_events_url":"https://api.github.com/users/asottile/received_events","type":"User","site_admin":false},"repo":{"id":152930011,"node_id":"MDEwOlJlcG9zaXRvcnkxNTI5MzAwMTE=","name":"pyflakes","full_name":"asottile/pyflakes","private":false,"owner":{"login":"asottile","id":1810591,"node_id":"MDQ6VXNlcjE4MTA1OTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1810591?v=4","gravatar_id":"","url":"https://api.github.com/users/asottile","html_url":"https://github.com/asottile","followers_url":"https://api.github.com/users/asottile/followers","following_url":"https://api.github.com/users/asottile/following{/other_user}","gists_url":"https://api.github.com/users/asottile/gists{/gist_id}","starred_url":"https://api.github.com/users/asottile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asottile/subscriptions","organizations_url":"https://api.github.com/users/asottile/orgs","repos_url":"https://api.github.com/users/asottile/repos","events_url":"https://api.github.com/users/asottile/events{/privacy}","received_events_url":"https://api.github.com/users/asottile/received_events","type":"User","site_admin":false},"html_url":"https://github.com/asottile/pyflakes","description":"A simple program which checks Python source files for errors","fork":true,"url":"https://api.github.com/repos/asottile/pyflakes","forks_url":"https://api.github.com/repos/asottile/pyflakes/forks","keys_url":"https://api.github.com/repos/asottile/pyflakes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asottile/pyflakes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asottile/pyflakes/teams","hooks_url":"https://api.github.com/repos/asottile/pyflakes/hooks","issue_events_url":"https://api.github.com/repos/asottile/pyflakes/issues/events{/number}","events_url":"https://api.github.com/repos/asottile/pyflakes/events","assignees_url":"https://api.github.com/repos/asottile/pyflakes/assignees{/user}","branches_url":"https://api.github.com/repos/asottile/pyflakes/branches{/branch}","tags_url":"https://api.github.com/repos/asottile/pyflakes/tags","blobs_url":"https://api.github.com/repos/asottile/pyflakes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asottile/pyflakes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asottile/pyflakes/git/refs{/sha}","trees_url":"https://api.github.com/repos/asottile/pyflakes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asottile/pyflakes/statuses/{sha}","languages_url":"https://api.github.com/repos/asottile/pyflakes/languages","stargazers_url":"https://api.github.com/repos/asottile/pyflakes/stargazers","contributors_url":"https://api.github.com/repos/asottile/pyflakes/contributors","subscribers_url":"https://api.github.com/repos/asottile/pyflakes/subscribers","subscription_url":"https://api.github.com/repos/asottile/pyflakes/subscription","commits_url":"https://api.github.com/repos/asottile/pyflakes/commits{/sha}","git_commits_url":"https://api.github.com/repos/asottile/pyflakes/git/commits{/sha}","comments_url":"https://api.github.com/repos/asottile/pyflakes/comments{/number}","issue_comment_url":"https://api.github.com/repos/asottile/pyflakes/issues/comments{/number}","contents_url":"https://api.github.com/repos/asottile/pyflakes/contents/{+path}","compare_url":"https://api.github.com/repos/asottile/pyflakes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asottile/pyflakes/merges","archive_url":"https://api.github.com/repos/asottile/pyflakes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asottile/pyflakes/downloads","issues_url":"https://api.github.com/repos/asottile/pyflakes/issues{/number}","pulls_url":"https://api.github.com/repos/asottile/pyflakes/pulls{/number}","milestones_url":"https://api.github.com/repos/asottile/pyflakes/milestones{/number}","notifications_url":"https://api.github.com/repos/asottile/pyflakes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asottile/pyflakes/labels{/name}","releases_url":"https://api.github.com/repos/asottile/pyflakes/releases{/id}","deployments_url":"https://api.github.com/repos/asottile/pyflakes/deployments","created_at":"2018-10-14T01:48:02Z","updated_at":"2018-10-14T01:48:04Z","pushed_at":"2019-01-01T06:46:32Z","git_url":"git://github.com/asottile/pyflakes.git","ssh_url":"git@github.com:asottile/pyflakes.git","clone_url":"https://github.com/asottile/pyflakes.git","svn_url":"https://github.com/asottile/pyflakes","homepage":"https://pypi.org/project/pyflakes","size":657,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"PyCQA:master","ref":"master","sha":"5ff36693b89351e5d74c696d3724c5afc5fe7510","user":{"login":"PyCQA","id":8749848,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg3NDk4NDg=","avatar_url":"https://avatars0.githubusercontent.com/u/8749848?v=4","gravatar_id":"","url":"https://api.github.com/users/PyCQA","html_url":"https://github.com/PyCQA","followers_url":"https://api.github.com/users/PyCQA/followers","following_url":"https://api.github.com/users/PyCQA/following{/other_user}","gists_url":"https://api.github.com/users/PyCQA/gists{/gist_id}","starred_url":"https://api.github.com/users/PyCQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyCQA/subscriptions","organizations_url":"https://api.github.com/users/PyCQA/orgs","repos_url":"https://api.github.com/users/PyCQA/repos","events_url":"https://api.github.com/users/PyCQA/events{/privacy}","received_events_url":"https://api.github.com/users/PyCQA/received_events","type":"Organization","site_admin":false},"repo":{"id":18508013,"node_id":"MDEwOlJlcG9zaXRvcnkxODUwODAxMw==","name":"pyflakes","full_name":"PyCQA/pyflakes","private":false,"owner":{"login":"PyCQA","id":8749848,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg3NDk4NDg=","avatar_url":"https://avatars0.githubusercontent.com/u/8749848?v=4","gravatar_id":"","url":"https://api.github.com/users/PyCQA","html_url":"https://github.com/PyCQA","followers_url":"https://api.github.com/users/PyCQA/followers","following_url":"https://api.github.com/users/PyCQA/following{/other_user}","gists_url":"https://api.github.com/users/PyCQA/gists{/gist_id}","starred_url":"https://api.github.com/users/PyCQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyCQA/subscriptions","organizations_url":"https://api.github.com/users/PyCQA/orgs","repos_url":"https://api.github.com/users/PyCQA/repos","events_url":"https://api.github.com/users/PyCQA/events{/privacy}","received_events_url":"https://api.github.com/users/PyCQA/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyCQA/pyflakes","description":"A simple program which checks Python source files for errors","fork":false,"url":"https://api.github.com/repos/PyCQA/pyflakes","forks_url":"https://api.github.com/repos/PyCQA/pyflakes/forks","keys_url":"https://api.github.com/repos/PyCQA/pyflakes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyCQA/pyflakes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyCQA/pyflakes/teams","hooks_url":"https://api.github.com/repos/PyCQA/pyflakes/hooks","issue_events_url":"https://api.github.com/repos/PyCQA/pyflakes/issues/events{/number}","events_url":"https://api.github.com/repos/PyCQA/pyflakes/events","assignees_url":"https://api.github.com/repos/PyCQA/pyflakes/assignees{/user}","branches_url":"https://api.github.com/repos/PyCQA/pyflakes/branches{/branch}","tags_url":"https://api.github.com/repos/PyCQA/pyflakes/tags","blobs_url":"https://api.github.com/repos/PyCQA/pyflakes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyCQA/pyflakes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyCQA/pyflakes/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyCQA/pyflakes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyCQA/pyflakes/statuses/{sha}","languages_url":"https://api.github.com/repos/PyCQA/pyflakes/languages","stargazers_url":"https://api.github.com/repos/PyCQA/pyflakes/stargazers","contributors_url":"https://api.github.com/repos/PyCQA/pyflakes/contributors","subscribers_url":"https://api.github.com/repos/PyCQA/pyflakes/subscribers","subscription_url":"https://api.github.com/repos/PyCQA/pyflakes/subscription","commits_url":"https://api.github.com/repos/PyCQA/pyflakes/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyCQA/pyflakes/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyCQA/pyflakes/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyCQA/pyflakes/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyCQA/pyflakes/contents/{+path}","compare_url":"https://api.github.com/repos/PyCQA/pyflakes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyCQA/pyflakes/merges","archive_url":"https://api.github.com/repos/PyCQA/pyflakes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyCQA/pyflakes/downloads","issues_url":"https://api.github.com/repos/PyCQA/pyflakes/issues{/number}","pulls_url":"https://api.github.com/repos/PyCQA/pyflakes/pulls{/number}","milestones_url":"https://api.github.com/repos/PyCQA/pyflakes/milestones{/number}","notifications_url":"https://api.github.com/repos/PyCQA/pyflakes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyCQA/pyflakes/labels{/name}","releases_url":"https://api.github.com/repos/PyCQA/pyflakes/releases{/id}","deployments_url":"https://api.github.com/repos/PyCQA/pyflakes/deployments","created_at":"2014-04-07T06:19:46Z","updated_at":"2019-01-01T13:10:39Z","pushed_at":"2019-01-01T13:10:35Z","git_url":"git://github.com/PyCQA/pyflakes.git","ssh_url":"git@github.com:PyCQA/pyflakes.git","clone_url":"https://github.com/PyCQA/pyflakes.git","svn_url":"https://github.com/PyCQA/pyflakes","homepage":"https://pypi.org/project/pyflakes","size":656,"stargazers_count":658,"watchers_count":658,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":94,"mirror_url":null,"archived":false,"open_issues_count":74,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":94,"open_issues":74,"watchers":658,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400"},"html":{"href":"https://github.com/PyCQA/pyflakes/pull/400"},"issue":{"href":"https://api.github.com/repos/PyCQA/pyflakes/issues/400"},"comments":{"href":"https://api.github.com/repos/PyCQA/pyflakes/issues/400/comments"},"review_comments":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400/comments"},"review_comment":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PyCQA/pyflakes/pulls/400/commits"},"statuses":{"href":"https://api.github.com/repos/PyCQA/pyflakes/statuses/e08d43d4e6ba78a8dd72c04e48b6f3539f0c54ce"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"sigmavirus24"}}