Repository: cython/cython

Issue:
[BUG]: annotating argument as list[some_type] raises CompileError
Trying to add pure-py annotation [here](https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/internals.pyx#L161)

```
-def append(self, others) -> BlockPlacement:
+def append(self, others: list[BlockPlacement]) -> BlockPlacement:
```

raises

```
pandas/_libs/internals.pyx:166:57: Compiler crash in IterationTransform
```


Discussion:

Resolving patch:
diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py
--- a/Cython/Compiler/Symtab.py
+++ b/Cython/Compiler/Symtab.py
@@ -822,6 +822,7 @@ def declare_cfunction(self, name, type, pos,
         if overridable:
             # names of cpdef functions can be used as variables and can be assigned to
             var_entry = Entry(name, cname, py_object_type)   # FIXME: cname?
+            var_entry.qualified_name = self.qualify_name(name)
             var_entry.is_variable = 1
             var_entry.is_pyglobal = 1
             var_entry.scope = entry.scope
@@ -1034,6 +1035,7 @@ def declare_builtin_cfunction(self, name, type, cname, python_equiv=None, utilit
             else:
                 python_equiv = EncodedString(python_equiv)
             var_entry = Entry(python_equiv, python_equiv, py_object_type)
+            var_entry.qualified_name = self.qualify_name(name)
             var_entry.is_variable = 1
             var_entry.is_builtin = 1
             var_entry.utility_code = utility_code
@@ -1057,6 +1059,7 @@ def declare_builtin_type(self, name, cname, utility_code = None, objstruct_cname
             type = self.lookup('type').type, # make sure "type" is the first type declared...
             pos = entry.pos,
             cname = entry.type.typeptr_cname)
+        var_entry.qualified_name = self.qualify_name(name)
         var_entry.is_variable = 1
         var_entry.is_cglobal = 1
         var_entry.is_readonly = 1
@@ -1244,6 +1247,7 @@ def declare_builtin(self, name, pos):
         else:
             entry.is_builtin = 1
             entry.name = name
+        entry.qualified_name = self.builtin_scope().qualify_name(name)
         return entry
 
     def find_module(self, module_name, pos, relative_level=-1):
@@ -1707,6 +1711,7 @@ def attach_var_entry_to_c_class(self, entry):
             type = Builtin.type_type,
             pos = entry.pos,
             cname = entry.type.typeptr_cname)
+        var_entry.qualified_name = entry.qualified_name
         var_entry.is_variable = 1
         var_entry.is_cglobal = 1
         var_entry.is_readonly = 1
@@ -2290,6 +2295,7 @@ def declare_builtin_cfunction(self, name, type, cname, utility_code = None):
         entry = self.declare_cfunction(name, type, None, cname, visibility='extern',
                                        utility_code=utility_code)
         var_entry = Entry(name, name, py_object_type)
+        var_entry.qualified_name = name
         var_entry.is_variable = 1
         var_entry.is_builtin = 1
         var_entry.utility_code = utility_code


Test patch:
diff --git a/tests/run/cython3.pyx b/tests/run/cython3.pyx
--- a/tests/run/cython3.pyx
+++ b/tests/run/cython3.pyx
@@ -1,6 +1,6 @@
-# cython: language_level=3, binding=True
+# cython: language_level=3, binding=True, annotation_typing=False
 # mode: run
-# tag: generators, python3, exceptions
+# tag: generators, python3, exceptions, gh2230, gh2811
 
 print(end='')  # test that language_level 3 applies immediately at the module start, for the first token.
 
@@ -619,6 +619,18 @@ def annotation_syntax(a: "test new test", b : "other" = 2, *args: "ARGS", **kwar
     return result
 
 
+def builtin_as_annotation(text: str):
+    # See https://github.com/cython/cython/issues/2811
+    """
+    >>> builtin_as_annotation("abc")
+    a
+    b
+    c
+    """
+    for c in text:
+        print(c)
+
+
 async def async_def_annotations(x: 'int') -> 'float':
     """
     >>> ret, arg = sorted(async_def_annotations.__annotations__.items())