From f595167d6f7712a54218a90fb8057c1f593fefaa Mon Sep 17 00:00:00 2001 From: Mikhail Beck Date: Mon, 8 Jan 2024 14:31:30 +0000 Subject: [PATCH] Update exasol/utils.py Co-authored-by: Nicola Coretti --- exasol/utils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/exasol/utils.py b/exasol/utils.py index d59814e..f4e2231 100644 --- a/exasol/utils.py +++ b/exasol/utils.py @@ -28,12 +28,22 @@ def optional_str_to_bool(value: Optional[str]) -> Optional[bool]: Case-insensitive "n", "no", "false" => False Any other value cause a ValueError exception. """ - if value is None: + if not value: return None - value_l = value.lower() - if value_l in ["y", "yes", "true"]: - return True - elif value_l in ["n", "no", "false"]: - return False - else: - raise ValueError("Invalid boolean value " + value) + + mapping = { + 'y': True, + 'yes': True, + 'true': True, + 'n': False, + 'no': False, + 'false': False, + } + key = value.lower() + + try: + result = mapping[key] + except KeyError as ex: + raise ValueError("Invalid boolean value " + value) from ex + + return result