Repository: cython/cython

Issue:
[BUG] Fused memoryviews returns `ValueError` instead of `TypeError`.
### Describe the bug

Fused memoryviews returns `ValueError` instead of `TypeError`.


### Code to reproduce the behaviour:

```cython
cimport numpy as cnp
import cython

ctypedef fused np_numeric_t:
    cnp.int8_t
    cnp.int16_t
    cnp.int32_t
    cnp.int64_t
    cnp.uint8_t
    cnp.uint16_t
    cnp.uint32_t
    cnp.uint64_t
    cnp.float32_t
    cnp.float64_t
    cnp.longdouble_t
    cnp.complex64_t
    cnp.complex128_t

@cython.initializedcheck(False)
def bandwidth_c(np_numeric_t[:, ::1]A):
    return
```


### Expected behaviour

## Cython 3
```python
>>> import numpy as np
>>> zz = np.zeros([5, 5], dtype='M')
>>> import fused
>>> fused.bandwidth_c(zz)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fused.pyx", line 31, in fused.__pyx_fused_cpdef
    @cython.initializedcheck(False)
ValueError: cannot include dtype 'M' in a buffer
```
## Cython 0.29.X:

```python
>>> import numpy as np
>>> zz = np.zeros([5, 5], dtype='M')
>>> import fused
>>> fused.bandwidth_c(zz)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fused.pyx", line 32, in fused.__pyx_fused_cpdef
    def bandwidth_c(np_numeric_t[:, ::1]A):
TypeError: No matching signature found
```

### OS

MacOS

### Python version

3.9.16

### Cython version

master

### Additional context

See discussion in mailing list: https://mail.python.org/pipermail/cython-devel/2023-April/005423.html


Discussion:

Resolving patch:
diff --git a/Cython/Compiler/FusedNode.py b/Cython/Compiler/FusedNode.py
--- a/Cython/Compiler/FusedNode.py
+++ b/Cython/Compiler/FusedNode.py
@@ -511,7 +511,7 @@ def _buffer_checks(self, buffer_types, pythran_types, pyx_code, decl_code, accep
             """
             try:
                 arg_as_memoryview = memoryview(arg)
-            except TypeError:
+            except (ValueError, TypeError):
                 pass
             """)
         with pyx_code.indenter("else:"):


Test patch:
diff --git a/tests/memoryview/numpy_memoryview.pyx b/tests/memoryview/numpy_memoryview.pyx
--- a/tests/memoryview/numpy_memoryview.pyx
+++ b/tests/memoryview/numpy_memoryview.pyx
@@ -734,3 +734,29 @@ def same_type_after_arrays_composite():
     cdef SameTypeAfterArraysStructComposite element
     arr = np.ones(2, np.asarray(<SameTypeAfterArraysStructComposite[:1]>&element).dtype)
     cdef SameTypeAfterArraysStructComposite[:] memview = arr
+
+ctypedef fused np_numeric_t:
+    np.float64_t
+
+def test_invalid_buffer_fused_memoryview(np_numeric_t[:] A):
+    """
+    >>> import numpy as np
+    >>> zz = np.zeros([5], dtype='M')
+    >>> test_invalid_buffer_fused_memoryview(zz)
+    Traceback (most recent call last):
+        ...
+    TypeError: No matching signature found
+    """
+    return
+
+ctypedef fused np_numeric_object_t:
+    np.float64_t[:]
+    object
+
+def test_valid_buffer_fused_memoryview(np_numeric_object_t A):
+    """
+    >>> import numpy as np
+    >>> zz = np.zeros([5], dtype='M')
+    >>> test_valid_buffer_fused_memoryview(zz)
+    """
+    return