# Buggy code
def check_generator_or_comprehension(
    self, gen: GeneratorExpr, type_name: str, id_for_messages: str
) -> Type:
    """Type check a generator expression or a list comprehension."""
    with self.chk.binder.frame_context():
        self.check_for_comp(gen)

        # Infer the type of the list comprehension by using a synthetic generic
        # callable type.
        tvdef = TypeVarDef("T", -1, [], self.chk.object_type())
        tv = TypeVarType(tvdef)
        constructor = CallableType(
            [tv],
            [nodes.ARG_POS],
            [None],
            self.chk.named_generic_type(type_name, [tv]),
            self.chk.named_type("builtins.function"),
            name=id_for_messages,
            variables=[tvdef],
        )
        return self.check_call(constructor, [gen.left_expr], [nodes.ARG_POS], gen)[0]


# 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 check_generator_or_comprehension(
    self, gen: GeneratorExpr, type_name: str, id_for_messages: str
) -> Type:
    """Type check a generator expression or a list comprehension."""
    with self.chk.binder.frame_context(can_skip=True, fall_through=0):
        self.check_for_comp(gen)

        # Infer the type of the list comprehension by using a synthetic generic
        # callable type.
        tvdef = TypeVarDef("T", -1, [], self.chk.object_type())
        tv = TypeVarType(tvdef)
        constructor = CallableType(
            [tv],
            [nodes.ARG_POS],
            [None],
            self.chk.named_generic_type(type_name, [tv]),
            self.chk.named_type("builtins.function"),
            name=id_for_messages,
            variables=[tvdef],
        )
        return self.check_call(constructor, [gen.left_expr], [nodes.ARG_POS], gen)[0]