# Buggy code
def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type:
    """Type check a super expression."""
    if e.info and e.info.bases:
        # TODO fix multiple inheritance etc
        if len(e.info.mro) < 2:
            self.chk.fail(
                "Internal error: unexpected mro for {}: {}".format(
                    e.info.name(), e.info.mro
                ),
                e,
            )
            return AnyType()
        for base in e.info.mro[1:]:
            if e.name in base.names or base == e.info.mro[-1]:
                if e.info.fallback_to_any and base == e.info.mro[-1]:
                    # There's an undefined base class, and we're
                    # at the end of the chain.  That's not an error.
                    return AnyType()
                if not self.chk.in_checked_function():
                    return AnyType()
                args = self.chk.scope.top_function().arguments
                # An empty args with super() is an error; we need something in declared_self
                if not args:
                    self.chk.fail(
                        "super() requires at least one positional argument", e
                    )
                    return AnyType()
                declared_self = args[0].variable.type
                return analyze_member_access(
                    name=e.name,
                    typ=fill_typevars(e.info),
                    node=e,
                    is_lvalue=False,
                    is_super=True,
                    is_operator=False,
                    builtin_type=self.named_type,
                    not_ready_callback=self.not_ready_callback,
                    msg=self.msg,
                    override_info=base,
                    original_type=declared_self,
                    chk=self.chk,
                )
        assert False, "unreachable"
    else:
        # Invalid super. This has been reported by the semantic analyzer.
        return AnyType()


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 6, in <module>
main(__file__)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only
options=options)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build
dispatch(sources, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1531, in dispatch
process_graph(graph, manager)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1768, in process_graph
process_stale_scc(graph, scc)
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1847, in process_stale_scc
graph[id].type_check_first_pass()
File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1453, in type_check_first_pass
self.type_checker.check_first_pass()
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 167, in check_first_pass
self.accept(d)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
stmt.accept(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 717, in accept
return visitor.visit_class_def(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 964, in visit_class_def
self.accept(defn.defs)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
stmt.accept(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 778, in accept
return visitor.visit_block(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1057, in visit_block
self.accept(s)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept
stmt.accept(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 819, in accept
return visitor.visit_assignment_stmt(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1064, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1140, in check_assignment
self.infer_variable_type(inferred, lvalue, self.expr_checker.accept(rvalue),
File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 2015, in accept
typ = node.accept(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 1492, in accept
return visitor.visit_super_expr(self)
File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 1835, in visit_super_expr
t = self.analyze_super(e, False)
File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 1854, in analyze_super
args = self.chk.scope.top_function().arguments
AttributeError: 'NoneType' object has no attribute 'arguments'

# Fixed code
def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type:
    """Type check a super expression."""
    if e.info and e.info.bases:
        # TODO fix multiple inheritance etc
        if len(e.info.mro) < 2:
            self.chk.fail(
                "Internal error: unexpected mro for {}: {}".format(
                    e.info.name(), e.info.mro
                ),
                e,
            )
            return AnyType()
        for base in e.info.mro[1:]:
            if e.name in base.names or base == e.info.mro[-1]:
                if e.info.fallback_to_any and base == e.info.mro[-1]:
                    # There's an undefined base class, and we're
                    # at the end of the chain.  That's not an error.
                    return AnyType()
                if not self.chk.in_checked_function():
                    return AnyType()
                if self.chk.scope.active_class() is not None:
                    self.chk.fail("super() outside of a method is not supported", e)
                    return AnyType()
                args = self.chk.scope.top_function().arguments
                # An empty args with super() is an error; we need something in declared_self
                if not args:
                    self.chk.fail(
                        "super() requires at least one positional argument", e
                    )
                    return AnyType()
                declared_self = args[0].variable.type
                return analyze_member_access(
                    name=e.name,
                    typ=fill_typevars(e.info),
                    node=e,
                    is_lvalue=False,
                    is_super=True,
                    is_operator=False,
                    builtin_type=self.named_type,
                    not_ready_callback=self.not_ready_callback,
                    msg=self.msg,
                    override_info=base,
                    original_type=declared_self,
                    chk=self.chk,
                )
        assert False, "unreachable"
    else:
        # Invalid super. This has been reported by the semantic analyzer.
        return AnyType()