`warnings.warn` function in the conventional `fit` method in `sklearn.cluster._spectral` raises a non-descriptive `TypeError`

### Describe the bug

I was emulating `GridSearch` methodology on fine-tuning `sklearn.cluster.SpectralClustering` with python `for` loops and encountered the error mentioned in the issue topic. This is weird because the error points to the call of `warnings.warn` from `cpython` (built-in). 

I tested the built-in function such that I run:
```python
warnings.warn(
    "The spectral clustering API has changed. ``fit``"
    "now constructs an affinity matrix from data. To use"
    " a custom affinity matrix, "
    "set ``affinity=precomputed``."
)
```
and it put out a warning conventionally acceptable. 

Hence, I have no idea why the error pointing to `warn` is raised instead of the warning itself or instead of the actual error while running the algorithm is traced and displayed. 

### Steps/Code to Reproduce

```python
from sklearn.cluster import SpectralClustering
from numpy import array

X = array([[ 1, 0, 1, 103, 1,   1,   1,   1, 1, 1, 1, 1, 9],
           [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
           [ 1, 0, 1,   0, 1,   1, 478, 478, 0, 1, 1, 1, 1],
           [ 1, 0, 1,  30, 1,   1,   5,   5, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   0, 1,   0,   1,   0, 1, 0, 4, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   0, 1, 0, 5, 1, 1],
           [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   5, 1,   1, 355, 177, 0, 1, 1, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   0, 1, 0, 6, 1, 1],
           [ 0, 0, 1,   1, 1,   0,   1,   1, 1, 0, 6, 6, 1],
           [ 0, 0, 1,   1, 1, 123,   1,   1, 1, 0, 2, 2, 1],
           [ 0, 0, 1,   1, 1,   1,   1,   1, 1, 1, 1, 1, 1],
           [ 0, 0, 1,   1, 1,   1,   0,   1, 0, 1, 1, 2, 1]],
          dtype=float)
    # sampled from actual dataset shaped `(2833, 532)`

clusterer = SpectralClustering(n_clusters=2,
                               eigen_solver='arpack',
                               random_state=42,
                               affinity='nearest_neighbors',
                               degree=2)

clusterer.fit(X)
```

Although the above reproducible codes involving `X.shape==(13, 13)`, the `.fit` sometimes works fine without encountering the error for extremely small varieties of sampling to `X.shape==(n_samples >= n_attributes, n_attributes)`.

### Expected Results

- A specific indication of the actual cause of the error is included in error traceback; or
- An alternative process was introduced in the module to work around the initial error.

### Actual Results

```python
------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [156], in <cell line: 24>()
      4 X = array([[ 1, 0, 1, 103, 1,   1,   1,   1, 1, 1, 1, 1, 9],
      5            [ 0, 0, 1,   1, 1,   1,   0,   0, 0, 1, 1, 1, 1],
      6            [ 1, 0, 1,   0, 1,   1, 478, 478, 0, 1, 1, 1, 1],
   (...)
     16            [ 0, 0, 1,   1, 1,   1,   0,   1, 0, 1, 1, 2, 1]],
     17           dtype=float)
     19 clusterer = SpectralClustering(n_clusters=2,
     20                                eigen_solver='arpack',
     21                                random_state=42,
     22                                affinity='nearest_neighbors',
     23                                degree=2)
---> 24 clusterer.fit(X)

File /opt/conda/lib/python3.9/site-packages/sklearn/cluster/_spectral.py:658, in SpectralClustering.fit(self, X, y)
    653 allow_squared = self.affinity in [
    654     "precomputed",
    655     "precomputed_nearest_neighbors",
    656 ]
    657 if X.shape[0] == X.shape[1] and not allow_squared:
--> 658     warnings.warn(
    659         "The spectral clustering API has changed. ``fit``"
    660         "now constructs an affinity matrix from data. To use"
    661         " a custom affinity matrix, "
    662         "set ``affinity=precomputed``."
    663     )
    665 check_scalar(
    666     self.n_clusters,
    667     "n_clusters",
   (...)
    670     include_boundaries="left",
    671 )
    673 check_scalar(
    674     self.n_init,
    675     "n_init",
   (...)
    678     include_boundaries="left",
    679 )

TypeError: issubclass() arg 2 must be a class or tuple of classes
```

### Versions

```shell
System:
    python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59)  [GCC 10.3.0]
executable: /opt/conda/bin/python
   machine: Linux-4.14.281-212.502.amzn2.x86_64-x86_64-with-glibc2.31

Python dependencies:
      sklearn: 1.1.1
          pip: 22.1.2
   setuptools: 59.8.0
        numpy: 1.22.4
        scipy: 1.8.1
       Cython: None
       pandas: 1.4.2
   matplotlib: 3.5.2
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /opt/conda/lib/libopenblasp-r0.3.20.so
        version: 0.3.20
threading_layer: pthreads
   architecture: SkylakeX
    num_threads: 4

       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /opt/conda/lib/libgomp.so.1.0.0
        version: None
    num_threads: 4
```

COMMENT:
OK weird, it would have been interesting to verify that my hunch about warnings.filters was indeed the issue ... thanks a lot anyway!

Labels: Bug, Needs Triage