Skip to content

Commit 3729574

Browse files
authored
chore: remove deprecated distutils references (#292)
1 parent c0ba13f commit 3729574

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

airbyte_cdk/sources/utils/transform.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44

55
import logging
6-
from distutils.util import strtobool
76
from enum import Flag, auto
87
from typing import Any, Callable, Dict, Generator, Mapping, Optional, cast
98

@@ -22,6 +21,28 @@
2221

2322
logger = logging.getLogger("airbyte")
2423

24+
_TRUTHY_STRINGS = ("y", "yes", "t", "true", "on", "1")
25+
_FALSEY_STRINGS = ("n", "no", "f", "false", "off", "0")
26+
27+
28+
def _strtobool(value: str, /) -> int:
29+
"""Mimic the behavior of distutils.util.strtobool.
30+
31+
From: https://docs.python.org/2/distutils/apiref.html#distutils.util.strtobool
32+
33+
> Convert a string representation of truth to true (1) or false (0).
34+
> True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. Raises
35+
> `ValueError` if val is anything else.
36+
"""
37+
normalized_str = value.lower().strip()
38+
if normalized_str in _TRUTHY_STRINGS:
39+
return 1
40+
41+
if normalized_str in _FALSEY_STRINGS:
42+
return 0
43+
44+
raise ValueError(f"Invalid boolean value: {normalized_str}")
45+
2546

2647
class TransformConfig(Flag):
2748
"""
@@ -129,7 +150,7 @@ def default_convert(original_item: Any, subschema: Dict[str, Any]) -> Any:
129150
return int(original_item)
130151
elif target_type == "boolean":
131152
if isinstance(original_item, str):
132-
return strtobool(original_item) == 1
153+
return _strtobool(original_item) == 1
133154
return bool(original_item)
134155
elif target_type == "array":
135156
item_types = set(subschema.get("items", {}).get("type", set()))

0 commit comments

Comments
 (0)