Skip to content
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

Crash on syntax error with unpacking #9137

Closed
remdragon opened this issue Jul 12, 2020 · 2 comments · Fixed by #11499
Closed

Crash on syntax error with unpacking #9137

remdragon opened this issue Jul 12, 2020 · 2 comments · Fixed by #11499
Labels

Comments

@remdragon
Copy link

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
import sys
from types import TracebackType
from typing import Optional as Opt, Tuple, Type, Union

class Event:
	exc_info: Opt[Union[Tuple[Type[BaseException],BaseException,TracebackType],Tuple[None,None,None]]] = None

def foo ( event: Event ) -> None:
	try:
		assert False
	except Exception:
		event.exc_info = *sys.exc_info() # mypy crashes on this syntax error
	
event = Event()
foo ( event )
print ( repr ( event.exc_info ) )
  • What is the actual behavior/output?
    see traceback below
  • What is the behavior/output you expect?
    report the syntax error without crashing
  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
    mypy 0.782
    Haven't tried master, this bug isn't a show stopper
  • What are the mypy flags you are using? (For example --strict-optional)
    --strict --implicit-reexport
boom.py:12: error: Can use starred expression only as assignment target
boom.py:12: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.782
Traceback (most recent call last):
  File "c:\python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python38-32\Scripts\mypy.exe\__main__.py", line 7, in <module>
    sys.exit(console_entry())
  File "c:\python38-32\lib\site-packages\mypy\__main__.py", line 8, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "c:\python38-32\lib\site-packages\mypy\main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 180, in build
    result = _build(
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 252, in _build
    graph = dispatch(sources, manager, stdout)
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 2626, in dispatch
    process_graph(graph, manager)
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 2949, in process_graph
    process_stale_scc(graph, scc, manager)
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 3047, in process_stale_scc
    graph[id].type_check_first_pass()
  File "c:\python38-32\lib\site-packages\mypy\build.py", line 2107, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 294, in check_first_pass
    self.accept(d)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 401, in accept
    stmt.accept(self)
  File "c:\python38-32\lib\site-packages\mypy\nodes.py", line 676, in accept
    return visitor.visit_func_def(self)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 726, in visit_func_def
    self._visit_func_def(defn)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 730, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 792, in check_func_item
    self.check_func_def(defn, typ, name)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 975, in check_func_def
    self.accept(item.body)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 401, in accept
    stmt.accept(self)
  File "c:\python38-32\lib\site-packages\mypy\nodes.py", line 1004, in accept
    return visitor.visit_block(self)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 1973, in visit_block
    self.accept(s)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 401, in accept
    stmt.accept(self)
  File "c:\python38-32\lib\site-packages\mypy\nodes.py", line 1234, in accept
    return visitor.visit_try_stmt(self)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 3308, in visit_try_stmt
    self.visit_try_without_finally(s, try_frame=bool(s.finally_body))
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 3363, in visit_try_without_finally
    self.accept(s.handlers[i])
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 401, in accept
    stmt.accept(self)
  File "c:\python38-32\lib\site-packages\mypy\nodes.py", line 1004, in accept
    return visitor.visit_block(self)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 1973, in visit_block
    self.accept(s)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 401, in accept
    stmt.accept(self)
  File "c:\python38-32\lib\site-packages\mypy\nodes.py", line 1062, in accept
    return visitor.visit_assignment_stmt(self)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 2011, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 2119, in check_assignment
    rvalue_type, lvalue_type, infer_lvalue_type = self.check_member_assignment(
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 2974, in check_member_assignment
    rvalue_type = self.check_simple_assignment(attribute_type, rvalue, context,
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 2945, in check_simple_assignment
    self.check_subtype(rvalue_type, lvalue_type, context, msg,
  File "c:\python38-32\lib\site-packages\mypy\checker.py", line 4482, in check_subtype
    if is_subtype(subtype, supertype):
  File "c:\python38-32\lib\site-packages\mypy\subtypes.py", line 93, in is_subtype
    return _is_subtype(left, right,
  File "c:\python38-32\lib\site-packages\mypy\subtypes.py", line 118, in _is_subtype
    is_subtype_of_item = any(is_subtype(orig_left, item,
  File "c:\python38-32\lib\site-packages\mypy\subtypes.py", line 118, in <genexpr>
    is_subtype_of_item = any(is_subtype(orig_left, item,
  File "c:\python38-32\lib\site-packages\mypy\subtypes.py", line 93, in is_subtype
    return _is_subtype(left, right,
  File "c:\python38-32\lib\site-packages\mypy\subtypes.py", line 135, in _is_subtype
    return left.accept(SubtypeVisitor(orig_right,
  File "c:\python38-32\lib\site-packages\mypy\types.py", line 1676, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
AssertionError:
boom.py:12: : note: use --pdb to drop into pdb
@JukkaL
Copy link
Collaborator

JukkaL commented Jul 22, 2020

I verified the crash. #8938 and #3825 seem related, but it's unclear if these are the exact same issue.

@progval
Copy link

progval commented Jun 4, 2021

A simpler example to reproduce this crash:

$ echo "*foo" > crashy.py 

$ mypy --show-traceback crashy.py 
crashy.py:1: error: Can use starred expression only as assignment target
crashy.py: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.820+dev.28718facbeea5b3c33ec96bc335bb018d3b0a395
Traceback (most recent call last):
  File "/home/dev/.local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/main.py", line 98, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 180, in build
    sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr, extra_plugins
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 253, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 2689, in dispatch
    process_graph(graph, manager)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 3013, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 3114, in process_stale_scc
    graph[id].finish_passes()
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 2209, in finish_passes
    free_tree(self.tree)
  File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 1954, in wrap_context
    yield
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 2196, in finish_passes
    self._patch_indirect_dependencies(self.type_checker().module_refs, self.type_map())
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/build.py", line 2223, in _patch_indirect_dependencies
    encountered = self.manager.indirection_detector.find_modules(types) | module_refs
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/indirection.py", line 27, in find_modules
    return self._visit(typs)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/indirection.py", line 41, in _visit
    modules = typ.accept(self)
  File "/home/dev/.local/lib/python3.7/site-packages/mypy/types.py", line 1737, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
AssertionError: 
crashy.py: : note: use --pdb to drop into pdb

This happens on the current master

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Nov 8, 2021
In general, mypy doesn't promise to be able to check the remainder of
your code in the presence of syntax errors, so just make this a blocking
error.

Fixes python#9137
Fixes python#3825 (most of the reports in this issue were fixed by python#8827)
@JelleZijlstra JelleZijlstra changed the title mypy 0.782 crash on syntax error Crash on syntax error with unpacking Apr 11, 2022
hauntsaninja added a commit that referenced this issue Nov 15, 2022
In general, mypy doesn't promise to be able to check the remainder of
your code in the presence of syntax errors, so just make this a blocking
error.

Fixes #9137
Fixes #3825 (most of the reports in this issue were fixed by #8827)

Co-authored-by: hauntsaninja <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants