# Buggy code
def declare_from_annotation(self, env, as_target=False):
    """Implements PEP 526 annotation typing in a fairly relaxed way.

    Annotations are ignored for global variables, Python class attributes and already declared variables.
    String literals are allowed and ignored.
    The ambiguous Python types 'int' and 'long' are ignored and the 'cython.int' form must be used instead.
    """
    if not env.directives["annotation_typing"]:
        return
    if env.is_module_scope or env.is_py_class_scope:
        # annotations never create global cdef names and Python classes don't support them anyway
        return
    name = self.name
    if self.entry or env.lookup_here(name) is not None:
        # already declared => ignore annotation
        return

    annotation = self.annotation
    if annotation.expr.is_string_literal:
        # name: "description" => not a type, but still a declared variable or attribute
        atype = None
    else:
        _, atype = annotation.analyse_type_annotation(env)
    if atype is None:
        atype = (
            unspecified_type
            if as_target and env.directives["infer_types"] != False
            else py_object_type
        )
    self.entry = env.declare_var(name, atype, self.pos, is_cdef=not as_target)
    self.entry.annotation = annotation.expr


# Traceback (Cython.Compiler.Errors.CompileError)
Compiling bug.py because it changed.
[1/1] Cythonizing bug.py

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
return arr
^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
return arr
^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized
Traceback (most recent call last):
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/users/augier3pi/Dev/transonic/transonic_cl/cythonize.py", line 11, in <module>
ext_modules=cythonize(path, language_level=3), include_dirs=[np.get_include()]
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1096, in cythonize
cythonize_one(*args)
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1219, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: bug.py

# Fixed code
def declare_from_annotation(self, env, as_target=False):
    """Implements PEP 526 annotation typing in a fairly relaxed way.

    Annotations are ignored for global variables, Python class attributes and already declared variables.
    String literals are allowed and ignored.
    The ambiguous Python types 'int' and 'long' are ignored and the 'cython.int' form must be used instead.
    """
    if not env.directives["annotation_typing"]:
        return
    if env.is_module_scope or env.is_py_class_scope:
        # annotations never create global cdef names and Python classes don't support them anyway
        return
    name = self.name
    if self.entry or env.lookup_here(name) is not None:
        # already declared => ignore annotation
        return

    annotation = self.annotation
    if annotation.expr.is_string_literal:
        # name: "description" => not a type, but still a declared variable or attribute
        atype = None
    else:
        _, atype = annotation.analyse_type_annotation(env)
    if atype is None:
        atype = (
            unspecified_type
            if as_target and env.directives["infer_types"] != False
            else py_object_type
        )
    if atype.is_fused and env.fused_to_specific:
        atype = atype.specialize(env.fused_to_specific)
    self.entry = env.declare_var(name, atype, self.pos, is_cdef=not as_target)
    self.entry.annotation = annotation.expr