Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated strtobool function #3760

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/grandchallenge/core/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from distutils.util import strtobool as strtobool_i
from functools import wraps


Expand All @@ -16,6 +15,17 @@ def wrapper(*args, **kwargs):
return wrapper


def strtobool(val) -> bool:
"""Return disutils.util.strtobool as a boolean."""
return bool(strtobool_i(val))
def strtobool(val):
"""Convert a string representation of truth to true or false.

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"invalid truth value {val}")
Loading