-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(bot): use exhaustiveness checking via NoReturn type (#614)
`NoReturn` is Python's `never` which we can use to help ensure we handle all cases. I tried looking for other places where we could use this, but didn't really find any easy places to add it. Also we need to use `is` when comparing enum variants due to mypy's backwards compatible refinement outlined in: python/mypy#6366
- Loading branch information
Showing
3 changed files
with
17 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import NoReturn | ||
|
||
|
||
def assert_never(value: NoReturn) -> NoReturn: | ||
""" | ||
Enable exhaustiveness checking when comparing against enums and unions | ||
of literals. | ||
""" | ||
raise Exception(f"expected never, got {value}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters