-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's now a helper function that enforces correct error handling when casting lists of optionals.
- Loading branch information
Showing
4 changed files
with
39 additions
and
20 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
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 |
---|---|---|
@@ -1,4 +1,17 @@ | ||
from typing import NewType | ||
from .mod_reload import reload_modules | ||
reload_modules(locals(), __package__, [], [".casts"]) # nopep8 | ||
|
||
from typing import List, NewType, Optional, Tuple, TypeVar | ||
from .casts import optional_list_cast | ||
|
||
ErrorMessage = NewType("ErrorMessage", str) | ||
NoError = ErrorMessage("") | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def ensureListIsGapless(l: List[Optional[T]]) -> Tuple[Optional[List[T]], ErrorMessage]: | ||
emptyIndices = [i for i, x in enumerate(l) if x is None] | ||
if len(emptyIndices) > 0: # a surface that was referenced did not get created | ||
return None, ErrorMessage(f"unexpected None at indices {emptyIndices}") | ||
return optional_list_cast(List[T], l), NoError |