Skip to content

no error when using generic in except block #17248

Open
@DetachHead

Description

@DetachHead
from typing import Generic, TypeVar

T = TypeVar("T")


class Foo(Exception, Generic[T]): ...


try:
    raise Foo
except Foo[int]: # no error, crashes at runtime
    ...

playground

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions