# Buggy code
def infer_type(self, env):
    # FIXME: this is way too redundant with analyse_types()
    node = self.analyse_as_cimported_attribute_node(env, target=False)
    if node is not None:
        return node.entry.type
    node = self.analyse_as_type_attribute(env)
    if node is not None:
        return node.entry.type
    obj_type = self.obj.infer_type(env)
    self.analyse_attribute(env, obj_type=obj_type)
    if obj_type.is_builtin_type and self.type.is_cfunction:
        # special case: C-API replacements for C methods of
        # builtin types cannot be inferred as C functions as
        # that would prevent their use as bound methods
        return py_object_type
    elif self.entry and self.entry.is_cmethod:
        # special case: bound methods should not be inferred
        # as their unbound method types
        return py_object_type
    return self.type


# Traceback (AttributeError)
$ cythonize -i -3 test_cpdef_func_ptr2.pyx
Compiling /home/leofang/dev/test_cpdef_func_ptr2.pyx because it changed.
[1/1] Cythonizing /home/leofang/dev/test_cpdef_func_ptr2.pyx
Traceback (most recent call last):
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/bin/cythonize", line 11, in <module>
sys.exit(main())
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Build/Cythonize.py", line 223, in main
cython_compile(path, options)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Build/Cythonize.py", line 106, in cython_compile
**options.options)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1102, in cythonize
cythonize_one(*args)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1208, in cythonize_one
result = compile_single(pyx_file, options, full_module_name=full_module_name)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Main.py", line 727, in compile_single
return run_pipeline(source, options, full_module_name)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Main.py", line 515, in run_pipeline
err, enddata = Pipeline.run_pipeline(pipeline, source)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Pipeline.py", line 355, in run_pipeline
data = run(phase, data)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Pipeline.py", line 335, in run
return phase(data)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
module_node.process_implementation(options, result)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/ModuleNode.py", line 143, in process_implementation
self.generate_c_code(env, options, result)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/ModuleNode.py", line 385, in generate_c_code
self.body.generate_function_definitions(env, code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 3174, in generate_function_definitions
FuncDefNode.generate_function_definitions(self, env, code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 1981, in generate_function_definitions
self.generate_function_body(env, code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 1743, in generate_function_body
self.body.generate_execution_code(code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 448, in generate_execution_code
stat.generate_execution_code(code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/Nodes.py", line 5988, in generate_execution_code
value.generate_evaluation_code(code)
File "/home/leofang/miniconda3/envs/cupy_cuda112_dev/lib/python3.7/site-packages/Cython/Compiler/ExprNodes.py", line 6052, in generate_evaluation_code
if value and value.is_attribute and value.obj.type.is_pyobject:
AttributeError: 'NoneType' object has no attribute 'is_pyobject'

# Fixed code
def infer_type(self, env):
    # FIXME: this is way too redundant with analyse_types()
    node = self.analyse_as_cimported_attribute_node(env, target=False)
    if node is not None:
        if node.entry.type and node.entry.type.is_cfunction:
            # special-case - function converted to pointer
            return PyrexTypes.CPtrType(node.entry.type)
        else:
            return node.entry.type
    node = self.analyse_as_type_attribute(env)
    if node is not None:
        return node.entry.type
    obj_type = self.obj.infer_type(env)
    self.analyse_attribute(env, obj_type=obj_type)
    if obj_type.is_builtin_type and self.type.is_cfunction:
        # special case: C-API replacements for C methods of
        # builtin types cannot be inferred as C functions as
        # that would prevent their use as bound methods
        return py_object_type
    elif self.entry and self.entry.is_cmethod:
        # special case: bound methods should not be inferred
        # as their unbound method types
        return py_object_type
    return self.type