# Buggy code
def __init__(
    self,
    pos,
    name,
    bases,
    doc,
    body,
    decorators=None,
    keyword_args=None,
    force_py3_semantics=False,
):
    StatNode.__init__(self, pos)
    self.name = name
    self.doc = doc
    self.body = body
    self.decorators = decorators
    self.bases = bases
    from . import ExprNodes

    if self.doc and Options.docstrings:
        doc = embed_position(self.pos, self.doc)
        doc_node = ExprNodes.StringNode(pos, value=doc)
    else:
        doc_node = None

    allow_py2_metaclass = not force_py3_semantics
    if keyword_args:
        allow_py2_metaclass = False
        self.is_py3_style_class = True
        if keyword_args.is_dict_literal:
            if keyword_args.key_value_pairs:
                for i, item in list(enumerate(keyword_args.key_value_pairs))[::-1]:
                    if item.key.value == "metaclass":
                        if self.metaclass is not None:
                            error(
                                item.pos,
                                "keyword argument 'metaclass' passed multiple times",
                            )
                        # special case: we already know the metaclass,
                        # so we don't need to do the "build kwargs,
                        # find metaclass" dance at runtime
                        self.metaclass = item.value
                        del keyword_args.key_value_pairs[i]
                self.mkw = keyword_args
            else:
                assert self.metaclass is not None
        else:
            # MergedDictNode
            self.mkw = ExprNodes.ProxyNode(keyword_args)

    if force_py3_semantics or self.bases or self.mkw or self.metaclass:
        if self.metaclass is None:
            if keyword_args and not keyword_args.is_dict_literal:
                # **kwargs may contain 'metaclass' arg
                mkdict = self.mkw
            else:
                mkdict = None
            if (
                not mkdict
                and self.bases.is_sequence_constructor
                and not self.bases.args
            ):
                pass  # no base classes => no inherited metaclass
            else:
                self.metaclass = ExprNodes.PyClassMetaclassNode(
                    pos, mkw=mkdict, bases=self.bases
                )
            needs_metaclass_calculation = False
        else:
            needs_metaclass_calculation = True

        self.dict = ExprNodes.PyClassNamespaceNode(
            pos,
            name=name,
            doc=doc_node,
            metaclass=self.metaclass,
            bases=self.bases,
            mkw=self.mkw,
        )
        self.classobj = ExprNodes.Py3ClassNode(
            pos,
            name=name,
            bases=self.bases,
            dict=self.dict,
            doc=doc_node,
            metaclass=self.metaclass,
            mkw=self.mkw,
            calculate_metaclass=needs_metaclass_calculation,
            allow_py2_metaclass=allow_py2_metaclass,
        )
    else:
        # no bases, no metaclass => old style class creation
        self.dict = ExprNodes.DictNode(pos, key_value_pairs=[])
        self.classobj = ExprNodes.ClassNode(
            pos, name=name, bases=bases, dict=self.dict, doc=doc_node
        )

    self.target = ExprNodes.NameNode(pos, name=name)
    self.class_cell = ExprNodes.ClassCellInjectorNode(self.pos)


# Traceback (AttributeError)
Compiling testfile.py because it changed.
[1/1] Cythonizing testfile.py
Traceback (most recent call last):
File "setup.py", line 12, in <module>
distutils.core.setup(ext_modules=Cython.Build.cythonize(packpaths, nthreads=buildthreads, compiler_directives={'language_level': 3, 'profile': True}, annotate=True))
File ".../Cython/Build/Dependencies.py", line 1096, in cythonize
cythonize_one(*args)
File ".../Cython/Build/Dependencies.py", line 1202, in cythonize_one
result = compile_single(pyx_file, options, full_module_name=full_module_name)
File ".../Cython/Compiler/Main.py", line 727, in compile_single
return run_pipeline(source, options, full_module_name)
File ".../Cython/Compiler/Main.py", line 515, in run_pipeline
err, enddata = Pipeline.run_pipeline(pipeline, source)
File ".../Cython/Compiler/Pipeline.py", line 355, in run_pipeline
data = run(phase, data)
File ".../Cython/Compiler/Pipeline.py", line 335, in run
return phase(data)
File ".../Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
module_node.process_implementation(options, result)
File ".../Cython/Compiler/ModuleNode.py", line 143, in process_implementation
self.generate_c_code(env, options, result)
File ".../Cython/Compiler/ModuleNode.py", line 385, in generate_c_code
self.body.generate_function_definitions(env, code)
File ".../Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File ".../Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File ".../Cython/Compiler/Nodes.py", line 3176, in generate_function_definitions
FuncDefNode.generate_function_definitions(self, env, code)
File ".../Cython/Compiler/Nodes.py", line 1983, in generate_function_definitions
self.generate_function_body(env, code)
File ".../Cython/Compiler/Nodes.py", line 1745, in generate_function_body
self.body.generate_execution_code(code)
File ".../Cython/Compiler/Nodes.py", line 448, in generate_execution_code
stat.generate_execution_code(code)
File ".../Cython/Compiler/Nodes.py", line 4601, in generate_execution_code
self.class_result.generate_evaluation_code(code)
File ".../Cython/Compiler/ExprNodes.py", line 773, in generate_evaluation_code
self.generate_result_code(code)
File ".../Cython/Compiler/ExprNodes.py", line 9034, in generate_result_code
self.bases.py_result(),
File ".../Cython/Compiler/ExprNodes.py", line 525, in py_result
return self.result_as(py_object_type)
File ".../Cython/Compiler/ExprNodes.py", line 516, in result_as
if (self.is_temp and self.type.is_pyobject and
AttributeError: 'NoneType' object has no attribute 'is_pyobject'

# Fixed code
def __init__(
    self,
    pos,
    name,
    bases,
    doc,
    body,
    decorators=None,
    keyword_args=None,
    force_py3_semantics=False,
):
    StatNode.__init__(self, pos)
    self.name = name
    self.doc = doc
    self.body = body
    self.decorators = decorators
    self.bases = bases
    from . import ExprNodes

    if self.doc and Options.docstrings:
        doc = embed_position(self.pos, self.doc)
        doc_node = ExprNodes.StringNode(pos, value=doc)
    else:
        doc_node = None

    allow_py2_metaclass = not force_py3_semantics
    if keyword_args:
        allow_py2_metaclass = False
        self.is_py3_style_class = True
        if keyword_args.is_dict_literal:
            if keyword_args.key_value_pairs:
                for i, item in list(enumerate(keyword_args.key_value_pairs))[::-1]:
                    if item.key.value == "metaclass":
                        if self.metaclass is not None:
                            error(
                                item.pos,
                                "keyword argument 'metaclass' passed multiple times",
                            )
                        # special case: we already know the metaclass,
                        # so we don't need to do the "build kwargs,
                        # find metaclass" dance at runtime
                        self.metaclass = item.value
                        del keyword_args.key_value_pairs[i]
                self.mkw = keyword_args
            else:
                assert self.metaclass is not None
        else:
            # MergedDictNode
            self.mkw = ExprNodes.ProxyNode(keyword_args)

    if force_py3_semantics or self.bases or self.mkw or self.metaclass:
        if self.metaclass is None:
            if keyword_args and not keyword_args.is_dict_literal:
                # **kwargs may contain 'metaclass' arg
                mkdict = self.mkw
            else:
                mkdict = None
            if (
                not mkdict
                and self.bases.is_sequence_constructor
                and not self.bases.args
            ):
                pass  # no base classes => no inherited metaclass
            else:
                self.metaclass = ExprNodes.PyClassMetaclassNode(
                    pos, class_def_node=self
                )
            needs_metaclass_calculation = False
        else:
            needs_metaclass_calculation = True

        self.dict = ExprNodes.PyClassNamespaceNode(
            pos, name=name, doc=doc_node, class_def_node=self
        )
        self.classobj = ExprNodes.Py3ClassNode(
            pos,
            name=name,
            class_def_node=self,
            doc=doc_node,
            calculate_metaclass=needs_metaclass_calculation,
            allow_py2_metaclass=allow_py2_metaclass,
        )
    else:
        # no bases, no metaclass => old style class creation
        self.dict = ExprNodes.DictNode(pos, key_value_pairs=[])
        self.classobj = ExprNodes.ClassNode(
            pos, name=name, class_def_node=self, doc=doc_node
        )

    self.target = ExprNodes.NameNode(pos, name=name)
    self.class_cell = ExprNodes.ClassCellInjectorNode(self.pos)