This module was listed with an override for disallow_any_generics=false due to the complexities around the generic type aliases it defines.
In short, the problem this module faces is that it converts between various types while preserving a type var (the type of exception being handled). However, attempting to explicitly declare that type var leads to mypy flagging runtime-safe usages which aren't provably type-safe.
To resolve these issues, a few steps are taken:
Tuples of hook functions with their relevant tests in the registry are replaced by a small dataclass
Where we once had (handleErrorX, errorIsOfTypeX), we now have _RegisteredHook[X]. This keeps the harmonious types declared in a way which type-checkers will find more palatable.
Overloads are declared for an internal helper which resolves class names to classes. Because the type of this function cannotbe deduced correctly by a type checker, several overloads are declared which "explain the type".
Drop support for a condition (test) function from the non-SDK error handler decorator. This is additional complexity, requiring overloads or similar "explanation" to make type-checking pass. But it is never actually used, and can therefore be safely dropped.
This module was listed with an override for
disallow_any_generics=false
due to the complexities around the generic type aliases it defines.In short, the problem this module faces is that it converts between various types while preserving a type var (the type of exception being handled). However, attempting to explicitly declare that type var leads to mypy flagging runtime-safe usages which aren't provably type-safe.
To resolve these issues, a few steps are taken:
Tuples of hook functions with their relevant tests in the registry are replaced by a small dataclass
Where we once had
(handleErrorX, errorIsOfTypeX)
, we now have_RegisteredHook[X]
. This keeps the harmonious types declared in a way which type-checkers will find more palatable.Overloads are declared for an internal helper which resolves class names to classes. Because the type of this function cannotbe deduced correctly by a type checker, several overloads are declared which "explain the type".
Drop support for a
condition
(test) function from the non-SDK error handler decorator. This is additional complexity, requiring overloads or similar "explanation" to make type-checking pass. But it is never actually used, and can therefore be safely dropped.