Skip to content

Uninformative message with fast-parser #1633

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
medullaskyline opened this issue Jun 3, 2016 · 1 comment
Closed

Uninformative message with fast-parser #1633

medullaskyline opened this issue Jun 3, 2016 · 1 comment

Comments

@medullaskyline
Copy link

To reproduce the bug, see https://github.com/medullaskyline/tuplebug

Running the test case:

virtualenv testcase -p `which python3`
source testcase/bin/activate
pip install -r requirements.txt

Annotating a tuple incorrectly will result in an uninformative traceback when running mypy with the --fast-parser flag.

This is the file I'm parsing: https://github.com/medullaskyline/tuplebug/blob/master/testcase.py

$ mypy --fast-parser --silent-imports --py2 --check-untyped-defs --disallow-untyped-defs testcase.py
Traceback (most recent call last):
  File "/srv/zulip-py3-venv/bin/mypy", line 6, in <module>
    main(__file__)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/main.py", line 54, in main
    res = type_check_only(sources, bin_dir, options)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/main.py", line 102, in type_check_only
    python_path=options.python_path)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 209, in build
    dispatch(sources, manager)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 1319, in dispatch
    graph = load_graph(sources, manager)
  File "/srv/zulip-py3-venv/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 "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 1106, in __init__
    self.parse_file()
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 1217, in parse_file
    self.tree = manager.parse_file(self.id, self.xpath, source)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 1171, in wrap_context
    yield
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 1217, in parse_file
    self.tree = manager.parse_file(self.id, self.xpath, source)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/build.py", line 449, in parse_file
    fast_parser=FAST_PARSER in self.flags)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/parse.py", line 88, in parse
    custom_typing_module=custom_typing_module)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/fastparse.py", line 69, in parse
    ).visit(ast)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/typed_ast/ast35.py", line 252, in visit
    return visitor(node)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/fastparse.py", line 221, in visit_Module
    body = self.fix_function_overloads(self.visit_list(mod.body))
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/fastparse.py", line 122, in visit_list
    return [self.visit(e) for e in l]
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/fastparse.py", line 122, in <listcomp>
    return [self.visit(e) for e in l]
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/typed_ast/ast35.py", line 252, in visit
    return visitor(node)
  File "/srv/zulip-py3-venv/lib/python3.5/site-packages/mypy/fastparse.py", line 90, in wrapper
    node = f(self, ast)
  File "/srv/zulip-py3-venv/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 "/srv/zulip-py3-venv/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.

This should be changed to the informative message that results when the --fast-parser flag is omitted

$ mypy --silent-imports --py2 --check-untyped-defs --disallow-untyped-defs testcase.py
testcase.py: note: In function "return_a_tuple":
testcase.py:3: error: Parse error before ,
@ddfisher
Copy link
Collaborator

ddfisher commented Jun 3, 2016

Thanks for the bug report! This was actually recently fixed in #1600.

@ddfisher ddfisher closed this as completed Jun 3, 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