Skip to content

Forgetting parens around arguments in python2 annotations crashes mypy fast-parser #1656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cpdean opened this issue Jun 5, 2016 · 1 comment

Comments

@cpdean
Copy link

cpdean commented Jun 5, 2016

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:

mypy --py2 testcase.py
testcase.py: note: In function "f":
testcase.py:1: error: Parse error before "int"

Actual behavior:

mypy --py2 --fast-parser testcase.py
Traceback (most recent call last):
  File "/Users/cdean/.virtualenvs/mypy/bin/mypy", line 6, in <module>
    main(__file__)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py", line 54, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/main.py", line 102, in type_check_only
    python_path=options.python_path)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 209, in build
    dispatch(sources, manager)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1319, in dispatch
    graph = load_graph(sources, manager)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1334, in load_graph
    st = State(id=bs.module, path=bs.path, source=bs.text, manager=manager)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1106, in __init__
    self.parse_file()
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1217, in parse_file
    self.tree = manager.parse_file(self.id, self.xpath, source)
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1175, in wrap_context
    report_internal_error(err, self.path, 0)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1171, in wrap_context
    yield
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 1217, in parse_file
    self.tree = manager.parse_file(self.id, self.xpath, source)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/build.py", line 449, in parse_file
    fast_parser=FAST_PARSER in self.flags)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/parse.py", line 88, in parse
    custom_typing_module=custom_typing_module)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 69, in parse
    ).visit(ast)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py", line 252, in visit
    return visitor(node)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 221, in visit_Module
    body = self.fix_function_overloads(self.visit_list(mod.body))
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 122, in visit_list
    return [self.visit(e) for e in l]
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 122, in <listcomp>
    return [self.visit(e) for e in l]
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py", line 252, in visit
    return visitor(node)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 90, in wrapper
    node = f(self, ast)
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/mypy/fastparse.py", line 242, in visit_FunctionDef
    func_type_ast = ast35.parse(n.type_comment, '<func_type>', 'func_type')
  File "/Users/cdean/.virtualenvs/mypy/lib/python3.5/site-packages/typed_ast/ast35.py", line 42, in parse
    return _ast35._parse(source, filename, mode)
SyntaxError: invalid syntax (<func_type>, line 1)

*** INTERNAL ERROR ***

testcase.py: error: Internal error -- please report a bug at https://github.com/python/mypy/issues

NOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.

Versions:

pip freeze
....
mypy-lang==0.4.2.dev0
....
typed-ast==0.5.1

on Python 3.5.0

@ddfisher
Copy link
Collaborator

ddfisher commented Jun 5, 2016

Thanks for the bug report! This has actually already been fixed in #1600.

@ddfisher ddfisher closed this as completed Jun 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants