From b0f2867372b70d2bf24efd566d6cdcde5bd5dbee Mon Sep 17 00:00:00 2001 From: Tymoteusz Kosman Date: Wed, 30 Jul 2025 22:38:26 +0200 Subject: [PATCH] Update str_to_bool function to include 'nope' as a valid false value --- guide/content/en/guide/running/configuration.md | 2 +- sanic/utils.py | 6 ++++-- setup.py | 12 +++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/guide/content/en/guide/running/configuration.md b/guide/content/en/guide/running/configuration.md index 71654c8731..54234c29b0 100644 --- a/guide/content/en/guide/running/configuration.md +++ b/guide/content/en/guide/running/configuration.md @@ -187,7 +187,7 @@ When loading from environment variables, Sanic will attempt to cast the values t In regards to `bool`, the following _case insensitive_ values are allowed: - **`True`**: `y`, `yes`, `yep`, `yup`, `t`, `true`, `on`, `enable`, `enabled`, `1` -- **`False`**: `n`, `no`, `f`, `false`, `off`, `disable`, `disabled`, `0` +- **`False`**: `n`, `no`, `f`, `nope`, `false`, `off`, `disable`, `disabled`, `0` If a value cannot be cast, it will default to a `str`. diff --git a/sanic/utils.py b/sanic/utils.py index cd1e3b4f09..40a91ce00c 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -18,7 +18,7 @@ def str_to_bool(val: str) -> bool: "true", "on", "enable", "enabled", "1" ) returns True. If val is in case insensitive ( - "n", "no", "f", "false", "off", "disable", "disabled", "0" + "n", "no", "f", "nope", "false", "off", "disable", "disabled", "0" ) returns False. Else Raise ValueError.""" @@ -36,7 +36,9 @@ def str_to_bool(val: str) -> bool: "1", }: return True - elif val in {"n", "no", "f", "false", "off", "disable", "disabled", "0"}: + elif val in { + "n", "no", "f", "nope", "false", "off", "disable", "disabled", "0" + }: return False else: raise ValueError(f"Invalid truth value {val}") diff --git a/setup.py b/setup.py index 632a0f0576..10b105c2a2 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,17 @@ def str_to_bool(val: str) -> bool: "1", }: return True - elif val in {"n", "no", "f", "false", "off", "disable", "disabled", "0"}: + elif val in { + "n", + "no", + "f", + "nope", + "false", + "off", + "disable", + "disabled", + "0", + }: return False else: raise ValueError(f"Invalid truth value {val}")