gurudesh/pytracebugs huggingface dataset:
# Buggy code
def allow_jump(self, index: int) -> None:
    # self.frames and self.options_on_return have different lengths
    # so make sure the index is positive
    if index < 0:
        index += len(self.options_on_return)
    frame = Frame()
    for f in self.frames[index + 1 :]:
        frame.update(f)
    self.options_on_return[index].append(frame)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def allow_jump(self, index: int) -> None:
    # self.frames and self.options_on_return have different lengths
    # so make sure the index is positive
    if index < 0:
        index += len(self.options_on_return)
    frame = Frame()
    for f in self.frames[index + 1 :]:
        frame.update(f)
        if f.unreachable:
            frame.unreachable = True
    self.options_on_return[index].append(frame)
# Buggy code
def visit_class_def(self, defn: ClassDef) -> Type:
    """Type check a class definition."""
    typ = defn.info
    self.errors.push_type(defn.name)
    self.enter_partial_types()
    old_binder = self.binder
    self.binder = ConditionalTypeBinder()
    with self.binder.frame_context():
        self.accept(defn.defs)
    self.binder = old_binder
    if not defn.has_incompatible_baseclass:
        # Otherwise we've already found errors; more errors are not useful
        self.check_multiple_inheritance(typ)
    self.leave_partial_types()
    self.errors.pop_type()


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_class_def(self, defn: ClassDef) -> Type:
    """Type check a class definition."""
    typ = defn.info
    self.errors.push_type(defn.name)
    self.enter_partial_types()
    old_binder = self.binder
    self.binder = ConditionalTypeBinder()
    with self.binder.top_frame_context():
        self.accept(defn.defs)
    self.binder = old_binder
    if not defn.has_incompatible_baseclass:
        # Otherwise we've already found errors; more errors are not useful
        self.check_multiple_inheritance(typ)
    self.leave_partial_types()
    self.errors.pop_type()
# Buggy code
def visit_block(self, b: Block) -> Type:
    if b.is_unreachable:
        return None
    for s in b.body:
        self.accept(s)
        if self.binder.breaking_out:
            break


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_block(self, b: Block) -> Type:
    if b.is_unreachable:
        return None
    for s in b.body:
        if self.binder.is_unreachable():
            break
        self.accept(s)
# Buggy code
def visit_while_stmt(self, s: WhileStmt) -> Type:
    """Type check a while statement."""
    self.accept_loop(IfStmt([s.expr], [s.body], None), s.else_body)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_while_stmt(self, s: WhileStmt) -> Type:
    """Type check a while statement."""
    self.accept_loop(
        IfStmt([s.expr], [s.body], None), s.else_body, exit_condition=s.expr
    )
# Buggy code
def visit_assert_stmt(self, s: AssertStmt) -> Type:
    self.accept(s.expr)

    # If this is asserting some isinstance check, bind that type in the following code
    true_map, _ = find_isinstance_check(s.expr, self.type_map)

    if true_map:
        for var, type in true_map.items():
            self.binder.push(var, type)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_assert_stmt(self, s: AssertStmt) -> Type:
    self.accept(s.expr)

    # If this is asserting some isinstance check, bind that type in the following code
    true_map, _ = self.find_isinstance_check(s.expr)

    self.push_type_map(true_map)
# Buggy code
def visit_raise_stmt(self, s: RaiseStmt) -> Type:
    """Type check a raise statement."""
    self.binder.breaking_out = True
    if s.expr:
        self.type_check_raise(s.expr, s)
    if s.from_expr:
        self.type_check_raise(s.from_expr, s)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_raise_stmt(self, s: RaiseStmt) -> Type:
    """Type check a raise statement."""
    if s.expr:
        self.type_check_raise(s.expr, s)
    if s.from_expr:
        self.type_check_raise(s.from_expr, s)
    self.binder.unreachable()
# Buggy code
def visit_break_stmt(self, s: BreakStmt) -> Type:
    self.binder.breaking_out = True
    self.binder.allow_jump(self.binder.loop_frames[-1] - 1)
    return None


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_break_stmt(self, s: BreakStmt) -> Type:
    self.binder.handle_break()
    return None
# Buggy code
def visit_continue_stmt(self, s: ContinueStmt) -> Type:
    self.binder.breaking_out = True
    self.binder.allow_jump(self.binder.loop_frames[-1])
    return None


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_continue_stmt(self, s: ContinueStmt) -> Type:
    self.binder.handle_continue()
    return None
# Buggy code
def analyze_cond_branch(
    self,
    map: Optional[Dict[Expression, Type]],
    node: Expression,
    context: Optional[Type],
) -> Type:
    with self.chk.binder.frame_context():
        if map:
            for var, type in map.items():
                self.chk.binder.push(var, type)
        return self.accept(node, context=context)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def analyze_cond_branch(
    self,
    map: Optional[Dict[Expression, Type]],
    node: Expression,
    context: Optional[Type],
) -> Type:
    with self.chk.binder.frame_context(can_skip=True, fall_through=0):
        if map is None:
            # We still need to type check node, in case we want to
            # process it for isinstance checks later
            self.accept(node, context=context)
            return UninhabitedType()
        self.chk.push_type_map(map)
        return self.accept(node, context=context)
# Buggy code
def __init__(self, value: int) -> None:
    self.value = value
    self.literal_hash = value


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, value: int) -> None:
    self.value = value
    self.literal_hash = ("Literal", value)
# Buggy code
def __init__(self, value: str) -> None:
    self.value = value
    self.literal_hash = value


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, value: str) -> None:
    self.value = value
    self.literal_hash = ("Literal", value)
# Buggy code
def __init__(self, value: float) -> None:
    self.value = value
    self.literal_hash = value


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, value: float) -> None:
    self.value = value
    self.literal_hash = ("Literal", value)
# Buggy code
def __init__(self, value: complex) -> None:
    self.value = value
    self.literal_hash = value


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, value: complex) -> None:
    self.value = value
    self.literal_hash = ("Literal", value)
# Buggy code
def __init__(self, base: Expression, index: Expression) -> None:
    self.base = base
    self.index = index
    self.analyzed = None
    if self.index.literal == LITERAL_YES:
        self.literal = self.base.literal
        self.literal_hash = ("Member", base.literal_hash, index.literal_hash)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, base: Expression, index: Expression) -> None:
    self.base = base
    self.index = index
    self.analyzed = None
    if self.index.literal == LITERAL_YES:
        self.literal = self.base.literal
        self.literal_hash = ("Index", base.literal_hash, index.literal_hash)
# Buggy code
def __init__(self, operators: List[str], operands: List[Expression]) -> None:
    self.operators = operators
    self.operands = operands
    self.method_types = []
    self.literal = min(o.literal for o in self.operands)
    self.literal_hash = (
        ("Comparison",) + tuple(operators) + tuple(o.literal_hash for o in operands)
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, operators: List[str], operands: List[Expression]) -> None:
    self.operators = operators
    self.operands = operands
    self.method_types = []
    self.literal = min(o.literal for o in self.operands)
    self.literal_hash = (
        (cast(Any, "Comparison"),)
        + tuple(operators)
        + tuple(o.literal_hash for o in operands)
    )
# Buggy code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = ("List",) + tuple(x.literal_hash for x in items)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = (cast(Any, "List"),) + tuple(x.literal_hash for x in items)
# Buggy code
def __init__(self, items: List[Tuple[Expression, Expression]]) -> None:
    self.items = items
    # key is None for **item, e.g. {'a': 1, **x} has
    # keys ['a', None] and values [1, x].
    if all(
        x[0] and x[0].literal == LITERAL_YES and x[1].literal == LITERAL_YES
        for x in items
    ):
        self.literal = LITERAL_YES
        self.literal_hash = ("Dict",) + tuple(
            (x[0].literal_hash, x[1].literal_hash) for x in items
        )  # type: ignore


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, items: List[Tuple[Expression, Expression]]) -> None:
    self.items = items
    # key is None for **item, e.g. {'a': 1, **x} has
    # keys ['a', None] and values [1, x].
    if all(
        x[0] and x[0].literal == LITERAL_YES and x[1].literal == LITERAL_YES
        for x in items
    ):
        self.literal = LITERAL_YES
        self.literal_hash = (cast(Any, "Dict"),) + tuple(
            (x[0].literal_hash, x[1].literal_hash) for x in items
        )
# Buggy code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = ("Tuple",) + tuple(x.literal_hash for x in items)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = (cast(Any, "Tuple"),) + tuple(x.literal_hash for x in items)
# Buggy code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = ("Set",) + tuple(x.literal_hash for x in items)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def __init__(self, items: List[Expression]) -> None:
    self.items = items
    if all(x.literal == LITERAL_YES for x in items):
        self.literal = LITERAL_YES
        self.literal_hash = (cast(Any, "Set"),) + tuple(x.literal_hash for x in items)
# Buggy code
def visit_class_def(self, tdef: ClassDef) -> None:
    for type in tdef.info.bases:
        self.analyze(type)
    # Recompute MRO now that we have analyzed all modules, to pick
    # up superclasses of bases imported from other modules in an
    # import loop. (Only do so if we succeeded the first time.)
    if tdef.info.mro:
        tdef.info.mro = []  # Force recomputation
        calculate_class_mro(tdef, self.fail)
    super().visit_class_def(tdef)


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\Program Files\Python35\Scripts\mypy", line 6, in <module>
main(__file__)
File "C:\Program Files\Python35\lib\site-packages\mypy\main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "C:\Program Files\Python35\lib\site-packages\mypy\main.py", line 102, in type_check_only
python_path=options.python_path)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 211, in build
dispatch(sources, manager)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1336, in dispatch
process_graph(graph, manager)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1467, in process_graph
process_stale_scc(graph, scc)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1497, in process_stale_scc
graph[id].type_check()
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1316, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 426, in visit_file
self.accept(d)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Program Files\Python35\lib\site-packages\mypy\nodes.py", line 650, in accept
return visitor.visit_class_def(self)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 1068, in visit_class_def
self.check_multiple_inheritance(typ)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 1093, in check_multiple_inheritance
if not (base1 in base2.mro or base2 in base1.mro):
AttributeError: 'NoneType' object has no attribute 'mro'

*** INTERNAL ERROR ***

mypybug.py:20: 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.

# Fixed code
def visit_class_def(self, tdef: ClassDef) -> None:
    for type in tdef.info.bases:
        self.analyze(type)
    # Recompute MRO now that we have analyzed all modules, to pick
    # up superclasses of bases imported from other modules in an
    # import loop. (Only do so if we succeeded the first time.)
    if tdef.info.mro:
        tdef.info.mro = []  # Force recomputation
        calculate_class_mro(tdef, self.fail_blocker)
    super().visit_class_def(tdef)
# Buggy code
def fail(self, msg: str, ctx: Context) -> None:
    self.errors.report(ctx.get_line(), msg)


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\Program Files\Python35\Scripts\mypy", line 6, in <module>
main(__file__)
File "C:\Program Files\Python35\lib\site-packages\mypy\main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "C:\Program Files\Python35\lib\site-packages\mypy\main.py", line 102, in type_check_only
python_path=options.python_path)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 211, in build
dispatch(sources, manager)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1336, in dispatch
process_graph(graph, manager)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1467, in process_graph
process_stale_scc(graph, scc)
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1497, in process_stale_scc
graph[id].type_check()
File "C:\Program Files\Python35\lib\site-packages\mypy\build.py", line 1316, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 426, in visit_file
self.accept(d)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 476, in accept
typ = node.accept(self)
File "C:\Program Files\Python35\lib\site-packages\mypy\nodes.py", line 650, in accept
return visitor.visit_class_def(self)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 1068, in visit_class_def
self.check_multiple_inheritance(typ)
File "C:\Program Files\Python35\lib\site-packages\mypy\checker.py", line 1093, in check_multiple_inheritance
if not (base1 in base2.mro or base2 in base1.mro):
AttributeError: 'NoneType' object has no attribute 'mro'

*** INTERNAL ERROR ***

mypybug.py:20: 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.

# Fixed code
def fail(self, msg: str, ctx: Context, *, blocker: bool = False) -> None:
    self.errors.report(ctx.get_line(), msg)
# Buggy code
def visit_break_stmt(self, s: BreakStmt) -> None:
    if self.loop_depth == 0:
        self.fail("'break' outside loop", s, True)


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/rbarton/mypy/scripts/mypy", line 6, in <module>
main(__file__)
[...]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 2028, in visit_break_stmt
self.binder.allow_jump(self.binder.loop_frames[-1] - 1)
IndexError: list index out of range

*** INTERNAL ERROR ***

break.py:1: 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.

# Fixed code
def visit_break_stmt(self, s: BreakStmt) -> None:
    if self.loop_depth == 0:
        self.fail("'break' outside loop", s, True, blocker=True)
# Buggy code
def visit_continue_stmt(self, s: ContinueStmt) -> None:
    if self.loop_depth == 0:
        self.fail("'continue' outside loop", s, True)


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/rbarton/mypy/scripts/mypy", line 6, in <module>
main(__file__)
[...]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 2028, in visit_break_stmt
self.binder.allow_jump(self.binder.loop_frames[-1] - 1)
IndexError: list index out of range

*** INTERNAL ERROR ***

break.py:1: 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.

# Fixed code
def visit_continue_stmt(self, s: ContinueStmt) -> None:
    if self.loop_depth == 0:
        self.fail("'continue' outside loop", s, True, blocker=True)
# Buggy code
def visit_yield_from_expr(self, e: YieldFromExpr) -> None:
    if not self.is_func_scope():  # not sure
        self.fail("'yield from' outside function", e)
    else:
        self.function_stack[-1].is_generator = True
    if e.expr:
        e.expr.accept(self)


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/rbarton/mypy/scripts/mypy", line 6, in <module>
main(__file__)
[...]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mypy/checker.py", line 2028, in visit_break_stmt
self.binder.allow_jump(self.binder.loop_frames[-1] - 1)
IndexError: list index out of range

*** INTERNAL ERROR ***

break.py:1: 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.

# Fixed code
def visit_yield_from_expr(self, e: YieldFromExpr) -> None:
    if not self.is_func_scope():  # not sure
        self.fail("'yield from' outside function", e, True, blocker=True)
    else:
        self.function_stack[-1].is_generator = True
    if e.expr:
        e.expr.accept(self)