# Buggy code
def generate_assignment_code(
    self,
    rhs,
    code,
    overloaded_assignment=False,
    exception_check=None,
    exception_value=None,
):
    self.generate_subexpr_evaluation_code(code)

    if self.type.is_pyobject:
        self.generate_setitem_code(rhs.py_result(), code)
    elif self.base.type is bytearray_type:
        value_code = self._check_byte_value(code, rhs)
        self.generate_setitem_code(value_code, code)
    elif (
        self.base.type.is_cpp_class
        and self.exception_check
        and self.exception_check == "+"
    ):
        if (
            overloaded_assignment
            and exception_check
            and self.exception_value != exception_value
        ):
            # Handle the case that both the index operator and the assignment
            # operator have a c++ exception handler and they are not the same.
            translate_double_cpp_exception(
                code,
                self.pos,
                self.type,
                self.result(),
                rhs.result(),
                self.exception_value,
                exception_value,
                self.in_nogil_context,
            )
        else:
            # Handle the case that only the index operator has a
            # c++ exception handler, or that
            # both exception handlers are the same.
            translate_cpp_exception(
                code,
                self.pos,
                "%s = %s;" % (self.result(), rhs.result()),
                self.result() if self.lhs.is_pyobject else None,
                self.exception_value,
                self.in_nogil_context,
            )
    else:
        code.putln("%s = %s;" % (self.result(), rhs.result()))

    self.generate_subexpr_disposal_code(code)
    self.free_subexpr_temps(code)
    rhs.generate_disposal_code(code)
    rhs.free_temps(code)


# Traceback (AttributeError)
python setup.py build_ext
Compiling cy_vec_wrapper.pyx because it changed.
[1/1] Cythonizing cy_vec_wrapper.pyx
/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/harding/tmp/vec_wrapper/cy_vec_wrapper.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
Traceback (most recent call last):
File "setup.py", line 12, in <module>
language='c++',           # generate C++ code
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 1086, in cythonize
cythonize_one(*args)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 1192, in cythonize_one
result = compile_single(pyx_file, options, full_module_name=full_module_name)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Main.py", line 725, in compile_single
return run_pipeline(source, options, full_module_name)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Main.py", line 513, in run_pipeline
err, enddata = Pipeline.run_pipeline(pipeline, source)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Pipeline.py", line 355, in run_pipeline
data = run(phase, data)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Pipeline.py", line 335, in run
return phase(data)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Pipeline.py", line 52, in generate_pyx_code_stage
module_node.process_implementation(options, result)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/ModuleNode.py", line 143, in process_implementation
self.generate_c_code(env, options, result)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/ModuleNode.py", line 379, in generate_c_code
self.body.generate_function_definitions(env, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 4839, in generate_function_definitions
self.body.generate_function_definitions(self.scope, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 442, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 3173, in generate_function_definitions
FuncDefNode.generate_function_definitions(self, env, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 1983, in generate_function_definitions
self.generate_function_body(env, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 1745, in generate_function_body
self.body.generate_execution_code(code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 448, in generate_execution_code
stat.generate_execution_code(code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 5169, in generate_execution_code
self.generate_assignment_code(code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/Nodes.py", line 5466, in generate_assignment_code
self.lhs.generate_assignment_code(self.rhs, code)
File "/home/harding/.local/lib/python2.7/site-packages/Cython/Compiler/ExprNodes.py", line 4105, in generate_assignment_code
self.result() if self.lhs.is_pyobject else None,
AttributeError: 'IndexNode' object has no attribute 'lhs'

# Fixed code
def generate_assignment_code(
    self,
    rhs,
    code,
    overloaded_assignment=False,
    exception_check=None,
    exception_value=None,
):
    self.generate_subexpr_evaluation_code(code)

    if self.type.is_pyobject:
        self.generate_setitem_code(rhs.py_result(), code)
    elif self.base.type is bytearray_type:
        value_code = self._check_byte_value(code, rhs)
        self.generate_setitem_code(value_code, code)
    elif (
        self.base.type.is_cpp_class
        and self.exception_check
        and self.exception_check == "+"
    ):
        if (
            overloaded_assignment
            and exception_check
            and self.exception_value != exception_value
        ):
            # Handle the case that both the index operator and the assignment
            # operator have a c++ exception handler and they are not the same.
            translate_double_cpp_exception(
                code,
                self.pos,
                self.type,
                self.result(),
                rhs.result(),
                self.exception_value,
                exception_value,
                self.in_nogil_context,
            )
        else:
            # Handle the case that only the index operator has a
            # c++ exception handler, or that
            # both exception handlers are the same.
            translate_cpp_exception(
                code,
                self.pos,
                "%s = %s;" % (self.result(), rhs.result()),
                self.result() if self.type.is_pyobject else None,
                self.exception_value,
                self.in_nogil_context,
            )
    else:
        code.putln("%s = %s;" % (self.result(), rhs.result()))

    self.generate_subexpr_disposal_code(code)
    self.free_subexpr_temps(code)
    rhs.generate_disposal_code(code)
    rhs.free_temps(code)