# Buggy code
def generate_result_code(self, code):
    cname = code.intern_identifier(self.name)
    py_mod_name = self.get_py_mod_name(code)
    qualname = self.get_py_qualified_name(code)
    if self.doc:
        doc_code = self.doc.result()
    else:
        doc_code = "(PyObject *) NULL"
    if self.mkw:
        mkw = self.mkw.py_result()
    else:
        mkw = "(PyObject *) NULL"
    if self.metaclass:
        metaclass = self.metaclass.py_result()
    else:
        metaclass = "(PyObject *) NULL"
    code.putln(
        "%s = __Pyx_Py3MetaclassPrepare(%s, %s, %s, %s, %s, %s, %s); %s"
        % (
            self.result(),
            metaclass,
            self.bases.result(),
            cname,
            qualname,
            mkw,
            py_mod_name,
            doc_code,
            code.error_goto_if_null(self.result(), self.pos),
        )
    )
    code.put_gotref(self.py_result())


# 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 generate_result_code(self, code):
    cname = code.intern_identifier(self.name)
    py_mod_name = self.get_py_mod_name(code)
    qualname = self.get_py_qualified_name(code)
    class_def_node = self.class_def_node
    null = "(PyObject *) NULL"
    doc_code = self.doc.result() if self.doc else null
    mkw = class_def_node.mkw.py_result() if class_def_node.mkw else null
    metaclass = (
        class_def_node.metaclass.py_result() if class_def_node.metaclass else null
    )
    code.putln(
        "%s = __Pyx_Py3MetaclassPrepare(%s, %s, %s, %s, %s, %s, %s); %s"
        % (
            self.result(),
            metaclass,
            class_def_node.bases.result(),
            cname,
            qualname,
            mkw,
            py_mod_name,
            doc_code,
            code.error_goto_if_null(self.result(), self.pos),
        )
    )
    code.put_gotref(self.py_result())