Title: Forgetting parens around arguments in python2 annotations crashes mypy fast-parser · Issue #1656 · python/mypy · GitHub
Open Graph Title: Forgetting parens around arguments in python2 annotations crashes mypy fast-parser · Issue #1656 · python/mypy
X Title: Forgetting parens around arguments in python2 annotations crashes mypy fast-parser · Issue #1656 · python/mypy
Description: When forgetting to wrap parentheses around the arguments of a function with python2 style annotations, the fast-parser crashes but the default parser does not. Example: def f(a, b): # type: int, int -> int return a + b Expected behavior:...
Open Graph Description: When forgetting to wrap parentheses around the arguments of a function with python2 style annotations, the fast-parser crashes but the default parser does not. Example: def f(a, b): # type: int, in...
X Description: When forgetting to wrap parentheses around the arguments of a function with python2 style annotations, the fast-parser crashes but the default parser does not. Example: def f(a, b): # type: int, in...
Opengraph URL: https://github.com/python/mypy/issues/1656
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Forgetting parens around arguments in python2 annotations crashes mypy fast-parser","articleBody":"When forgetting to wrap parentheses around the arguments of a function with python2 style annotations, the fast-parser crashes but the default parser does not.\n\nExample:\n\n``` python\ndef f(a, b):\n # type: int, int -> int\n return a + b\n```\n\nExpected behavior:\n\n```\nmypy --py2 testcase.py\ntestcase.py: note: In function \"f\":\ntestcase.py:1: error: Parse error before \"int\"\n```\n\nActual behavior:\n\n```\nmypy --py2 --fast-parser testcase.py\nTraceback (most recent call last):\n File \"/Users/cdean/.virtualenvs/mypy/bin/mypy\", line 6, in \u003cmodule>\n main(__file__)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py\", line 54, in main\n res = type_check_only(sources, bin_dir, options)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py\", line 102, in type_check_only\n python_path=options.python_path)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 209, in build\n dispatch(sources, manager)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1319, in dispatch\n graph = load_graph(sources, manager)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1334, in load_graph\n st = State(id=bs.module, path=bs.path, source=bs.text, manager=manager)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1106, in __init__\n self.parse_file()\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1217, in parse_file\n self.tree = manager.parse_file(self.id, self.xpath, source)\n File \"/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py\", line 77, in __exit__\n self.gen.throw(type, value, traceback)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1175, in wrap_context\n report_internal_error(err, self.path, 0)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1171, in wrap_context\n yield\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 1217, in parse_file\n self.tree = manager.parse_file(self.id, self.xpath, source)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py\", line 449, in parse_file\n fast_parser=FAST_PARSER in self.flags)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/parse.py\", line 88, in parse\n custom_typing_module=custom_typing_module)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 69, in parse\n ).visit(ast)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py\", line 252, in visit\n return visitor(node)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 221, in visit_Module\n body = self.fix_function_overloads(self.visit_list(mod.body))\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 122, in visit_list\n return [self.visit(e) for e in l]\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 122, in \u003clistcomp>\n return [self.visit(e) for e in l]\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py\", line 252, in visit\n return visitor(node)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 90, in wrapper\n node = f(self, ast)\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py\", line 242, in visit_FunctionDef\n func_type_ast = ast35.parse(n.type_comment, '\u003cfunc_type>', 'func_type')\n File \"/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py\", line 42, in parse\n return _ast35._parse(source, filename, mode)\nSyntaxError: invalid syntax (\u003cfunc_type>, line 1)\n\n*** INTERNAL ERROR ***\n\ntestcase.py: error: Internal error -- please report a bug at https://github.com/python/mypy/issues\n\nNOTE: you can use \"mypy --pdb ...\" to drop into the debugger when this happens.\n```\n\nVersions:\n\n```\npip freeze\n....\nmypy-lang==0.4.2.dev0\n....\ntyped-ast==0.5.1\n```\n\non Python 3.5.0\n","author":{"url":"https://github.com/cpdean","@type":"Person","name":"cpdean"},"datePublished":"2016-06-05T20:49:24Z","url":"https://github.com/python/mypy/issues/1656"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:67eab281-9d6c-e258-4995-bbefff85d42d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5F0:3E1398:BF773E:100B22E:6B004DFC |
| html-safe-nonce | 0abfb0f103047ad8c4b03d229fbc5a51d9573b83cbbe7f66ad71347c72fd9d5f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUYwOjNFMTM5ODpCRjc3M0U6MTAwQjIyRTo2QjAwNERGQyIsInZpc2l0b3JfaWQiOiI3NjYzNDYzNDc3OTEwMTEzMjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6198b36069fb2e739c8e11d48e50424892a5b5f31dff3c4c5c86607aebfa9024 |
| hovercard-subject-tag | issue:158573958 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/1656/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1c57c8e685b47857f298e5e82437b6b9de0af6f495bece13b6eadbb4d6ab4200/python/mypy/issues/1656 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1c57c8e685b47857f298e5e82437b6b9de0af6f495bece13b6eadbb4d6ab4200/python/mypy/issues/1656 |
| og:image:alt | When forgetting to wrap parentheses around the arguments of a function with python2 style annotations, the fast-parser crashes but the default parser does not. Example: def f(a, b): # type: int, in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cpdean |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width