File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed
src/sagemaker/modules/train/container_drivers/common
tests/unit/sagemaker/modules/train/container_drivers Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -124,8 +124,6 @@ def safe_deserialize(data: Any) -> Any:
124
124
125
125
This function handles the following cases:
126
126
1. If `data` is not a string, it returns the input as-is.
127
- 2. If `data` is a string and matches common boolean values ("true" or "false"),
128
- it returns the corresponding boolean value (True or False).
129
127
3. If `data` is a JSON-encoded string, it attempts to deserialize it using `json.loads()`.
130
128
4. If `data` is a string but cannot be decoded as JSON, it returns the original string.
131
129
@@ -134,13 +132,6 @@ def safe_deserialize(data: Any) -> Any:
134
132
"""
135
133
if not isinstance (data , str ):
136
134
return data
137
-
138
- lower_data = data .lower ()
139
- if lower_data in ["true" ]:
140
- return True
141
- if lower_data in ["false" ]:
142
- return False
143
-
144
135
try :
145
136
return json .loads (data )
146
137
except json .JSONDecodeError :
Original file line number Diff line number Diff line change @@ -59,8 +59,14 @@ def test_safe_deserialize_not_a_string():
59
59
def test_safe_deserialize_boolean_strings ():
60
60
assert safe_deserialize ("true" ) is True
61
61
assert safe_deserialize ("false" ) is False
62
- assert safe_deserialize ("True" ) is True
63
- assert safe_deserialize ("False" ) is False
62
+
63
+ # The below are not valid JSON booleans
64
+ assert safe_deserialize ("True" ) == "True"
65
+ assert safe_deserialize ("False" ) == "False"
66
+ assert safe_deserialize ("TRUE" ) == "TRUE"
67
+ assert safe_deserialize ("FALSE" ) == "FALSE"
68
+ assert safe_deserialize ("tRuE" ) == "tRuE"
69
+ assert safe_deserialize ("fAlSe" ) == "fAlSe"
64
70
65
71
66
72
def test_safe_deserialize_valid_json_string ():
You can’t perform that action at this time.
0 commit comments