Repository: cython/cython

Issue:
[ENH] Print warning when type is unkown in pure-python memoryview
### Is your feature request related to a problem? Please describe.

Consider following cython code:
```cython
# cython is *not* imported
def foo(bar: cython.int[:]):
    pass
```
This code is compiled successfully without any warning even though `cython.int` type is ignored.

### Describe the solution you'd like.

When annotation type is not recognized a warning should be raised:
```
warning: deleteme.py:2:19: Unknown type declaration 'cython.int' in annotation, ignoring
```
This is the same behavior as we have already for simple types:
```python
# cython is *not* imported
def foo(bar: cython.int):
    pass
```

### Describe alternatives you've considered.

Alternative is to keep as it is but this can end up with stupid mistakes as mine - see issue #5649

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -14514,6 +14514,8 @@ def analyse_as_type(self, env):
 
     def _warn_on_unknown_annotation(self, env, annotation):
         """Method checks for cases when user should be warned that annotation contains unknown types."""
+        if isinstance(annotation, SliceIndexNode):
+            annotation = annotation.base
         if annotation.is_name:
             # Validate annotation in form `var: type`
             if not env.lookup(annotation.name):


Test patch:
diff --git a/tests/errors/pure_warnings.py b/tests/errors/pure_warnings.py
--- a/tests/errors/pure_warnings.py
+++ b/tests/errors/pure_warnings.py
@@ -18,6 +18,8 @@ def main():
     foo8: (1 + x).b
     foo9: mod.a.b
     foo10: func().b
+    foo11: Bar[:, :, :]  # warning
+    foo12: cython.int[:, ::1]
     with cython.annotation_typing(False):
         foo8: Bar = 1
         foo9: stdint.bar = 5
@@ -25,16 +27,19 @@ def main():
 
 
 @cython.cfunc
-def bar() -> cython.bar:
+def bar() -> cython.bar:  # error
     pass
 
 
 @cython.cfunc
-def bar2() -> Bar:
+def bar2() -> Bar:  # warning
     pass
 
 @cython.cfunc
-def bar3() -> stdint.bar:
+def bar3() -> stdint.bar:  # error
+    pass
+
+def bar4(a: cython.foo[:]):  # error
     pass
 
 _WARNINGS = """
@@ -43,21 +48,26 @@ def bar3() -> stdint.bar:
 18:17: Unknown type declaration in annotation, ignoring
 19:15: Unknown type declaration in annotation, ignoring
 20:17: Unknown type declaration in annotation, ignoring
-33:14: Unknown type declaration 'Bar' in annotation, ignoring
-37:20: Unknown type declaration 'stdint.bar' in annotation, ignoring
+21:14: Unknown type declaration in annotation, ignoring
+35:14: Unknown type declaration 'Bar' in annotation, ignoring
+39:20: Unknown type declaration 'stdint.bar' in annotation, ignoring
 
 # Spurious warnings from utility code - not part of the core test
 25:10: 'cpdef_method' redeclared
 36:10: 'cpdef_cname_method' redeclared
 961:29: Ambiguous exception value, same as default return value: 0
+961:29: Ambiguous exception value, same as default return value: 0
 1002:46: Ambiguous exception value, same as default return value: 0
+1002:46: Ambiguous exception value, same as default return value: 0
+1092:29: Ambiguous exception value, same as default return value: 0
 1092:29: Ambiguous exception value, same as default return value: 0
 """
 
 _ERRORS = """
 17:16: Unknown type declaration 'cython.bar' in annotation
-28:13: Not a type
-28:19: Unknown type declaration 'cython.bar' in annotation
-33:14: Not a type
-37:14: Not a type
+30:13: Not a type
+30:19: Unknown type declaration 'cython.bar' in annotation
+35:14: Not a type
+39:14: Not a type
+42:18: Unknown type declaration 'cython.foo[:]' in annotation
 """