New GitHub issue #119094 from DetachHead:<br>
<hr>
<pre>
# Bug report
### Bug description:
```python
from typing import Generic, TypeVar
T = TypeVar("T")
class Foo(Exception, Generic[T]): ...
try:
raise Foo
except Foo[int]:
...
```
this causes the following runtime error:
```
TypeError: catching classes that do not inherit from BaseException is not allowed
```
this was originally raised on pyright: https://github.com/microsoft/pyright/issues/7921, however this seems more like a bug in python. as @erictraut [points out](https://github.com/microsoft/pyright/issues/7921#issuecomment-2113718416), generic aliases are an implementation detail and should act as normal classes in cases like this:
> > it's a generic alias object
>
> That's an implementation detail, not part of the mental model for most developers. In most cases, `Foo[int]` acts like `Foo` at runtime. For example, you can call `Foo[int]` to invoke `Foo`'s constructor, and `Foo[int].x` accesses class variable `x` on `Foo`. Clearly, the implementers of generic types went through some trouble to make it appear from a developer's perspective that `Foo[int]` is a class. It's not clear to me whether it was an oversight that `Foo[int]` cannot be used in an `except` statement.
### CPython versions tested on:
3.12
### Operating systems tested on:
Windows
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/119094">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>