-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace strtobool by custom impl
- Loading branch information
Showing
8 changed files
with
29 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Module providing `strtobool` function as replacement of distutils.strtobool.""" | ||
|
||
|
||
def strtobool(val: str) -> bool: | ||
"""Convert a string representation of truth to bool. | ||
True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. | ||
Raises TypeError if `val` is not string. | ||
Raises ValueError if `val` is anything else. | ||
""" | ||
if not isinstance(val, str): | ||
raise TypeError(f"`{val}` is not of type str") | ||
trues = ("y", "yes", "t", "true", "on", "1") | ||
falses = ("n", "no", "f", "false", "off", "0") | ||
|
||
val = val.lower() | ||
if val in trues: | ||
return True | ||
if val in falses: | ||
return False | ||
raise ValueError(f"`{val}` not in {trues + falses}") |
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
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