assert_never raises different exception than documented · Issue #1857 · gitpython-developers/GitPython (original) (raw)
git.types.assert_never
is documented to raise AssertionError
if raise_error
is True
and exc
is None
:
If raise_error is True, will also raise AssertionError or the Exception passed to exc. |
---|
But it actually raises ValueError
in this situation, its full implementation being:
if raise_error: |
---|
if exc is None: |
raise ValueError(f"An unhandled Literal ({inp}) in an if/else chain was found") |
else: |
raise exc |
For comparison. there is an assert_never
function in Python's typing
module since 3.11 (and in typing_extensions
). This function is similar but only has one parameter--which the first parameter of git.types.assert_never
corresponds to--and it documents that it raises an exception if called at runtime, but does not document the type of exception raised. At least currently in Python 3.12, it raises AssertionError.
The GitPython function is a public member of git.types
, and it is used internally in GitPython. I don't know if the docstring should be fixed to describe the existing behavior, or if that behavior should itself be considered the bug here and changed to match the docstring.