typelets.runtime¶
Utility for asserting never types with more flexibility.
Added in version 1.1.
Functions
|
Raise an exception far an invalid type. |
- typelets.runtime.raise_invalid_type(value: Never, message: str, exception_type: type[Exception] = <class 'ValueError'>) Never[source]¶
Raise an exception far an invalid type.
In many cases, especially for public APIs, we want runtime checking for argument types as well as type checking. This method can be used as a type guard in those cases where that code would be flagged by the type checkers as unreachable.
This works similarly to
typing.assert_never(), but allows customization of the exception type and message, sinceAssertionErroris not great from an API standpoint.Added in version 1.1.