no error when using generic in `except` block
Open
Nobody has claimed this yet.
bug
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import Generic, TypeVar
T = TypeVar("T")
class Foo(Exception, Generic[T]): ...
try:
raise Foo
except Foo[int]: # no error, crashes at runtime
...
this should be a type error because it fails at runtime with the following exception:
TypeError: catching classes that do not inherit from BaseException is not allowed
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python reproducer with mypy and inspect how generic exception types are handled in an except clause. Trace the relevant type-checking path and add a regression test for this example; done means mypy reports a type error instead of accepting code that fails at runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100