Commit f83b056
committed
Revise assert_never
This revises the docstring of git.types.assert_never to more
clearly express its semantics and usage, to use the type names used
in the typing module, typing_extensions package, and mypy. This
expands some parts when doing so seemed to benefit clarity.
The docstring had previously said AssertionError was raised, but
the code raised ValueError. For now I've adjusted the docstring to
be accurate to the code's behavior, but maybe this should change.
I also removed the part about the mypy error being on variable
creation, since I am not clear on what that was referring to, and
if it means the first name binding operation for a variable in its
scope, then I am not sure why that would be where an error message
would be expected when using assert_never.
Finally, this slightly adjusts the message:
- "Literal" is decapitalized, to decrease confusion if the default
message is used when matching on something not a typing.Literal.
- The exception message prints the unexpected value's repr rather
than its str, since the repr, when different from the str, is
usually the representation more useful for debugging.1 parent b2c3d8b commit f83b056
1 file changed
+14
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
80 | 84 | | |
81 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
82 | 88 | | |
83 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
87 | | - | |
| 95 | + | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
| |||
0 commit comments