Skip to content

Commit

Permalink
Replace deprecated strtobool function
Browse files Browse the repository at this point in the history
  • Loading branch information
koopmant committed Dec 18, 2024
1 parent 8b24beb commit 24d6916
Showing 1 changed file with 14 additions and 4 deletions.
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}")

0 comments on commit 24d6916

Please sign in to comment.