From e57bea28f716f0900750f6253fe48b31e9a043a2 Mon Sep 17 00:00:00 2001 From: Stephen Sadowski Date: Tue, 1 Feb 2022 14:11:52 -0600 Subject: [PATCH] fix: update sanic.utils.str_to_bool to match deprecated strtobool, changed setup.py to use sanic.utils.str_to_bool --- sanic/utils.py | 33 ++++++++------------------------- setup.py | 15 +-------------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/sanic/utils.py b/sanic/utils.py index 51d94d08..f972eed1 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -11,35 +11,18 @@ from sanic.helpers import import_string def str_to_bool(val: str) -> bool: - """Takes string and tries to turn it into bool as human would do. + """ + reimplement strtobool per PEP 632 and python 3.12 deprecation - If val is in case insensitive ( - "y", "yes", "yep", "yup", "t", - "true", "on", "enable", "enabled", "1" - ) returns True. - If val is in case insensitive ( - "n", "no", "f", "false", "off", "disable", "disabled", "0" - ) returns False. - Else Raise ValueError.""" - - val = val.lower() - if val in { - "y", - "yes", - "yep", - "yup", - "t", - "true", - "on", - "enable", - "enabled", - "1", - }: + 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. + """ + if val.lower() in ["y", "yes", "t", "true", "on", "1"]: return True - elif val in {"n", "no", "f", "false", "off", "disable", "disabled", "0"}: + elif val.lower() in ["n", "no", "f", "false", "off", "0"]: return False else: - raise ValueError(f"Invalid truth value {val}") + raise ValueError(f'String value {val} cannot be converted to bool') def load_module_from_file_location( diff --git a/setup.py b/setup.py index 5877c7dc..c92cfa06 100644 --- a/setup.py +++ b/setup.py @@ -9,20 +9,7 @@ import sys from setuptools import find_packages, setup from setuptools.command.test import test as TestCommand - -def strtobool(query: str) -> bool: - """ - reimplement strtobool per PEP 632 and python 3.12 deprecation - - 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. - """ - if query.lower() in ["y", "yes", "t", "true", "on", "1"]: - return True - elif query.lower() in ["n", "no", "f", "false", "off", "0"]: - return False - else: - raise ValueError(f'String value {query} cannot be converted to bool') +from sanic.utils import str_to_bool as strtobool class PyTest(TestCommand): """