Merged in bugfix/flatten_singleton_list_ints_problem (pull request #488)
Bugfix/flatten singleton list ints problem * Fix flatten_singleton_string_list to handle non-list int strings and improve test coverage * Fix test_flatten_singleton_string_list to handle integer input correctly Approved-by: Katon Minhas
This commit is contained in:
committed by
Katon Minhas
parent
c50f78e84d
commit
297926839a
@@ -79,8 +79,13 @@ def flatten_singleton_string_list(list_str: str) -> str:
|
||||
try:
|
||||
# Convert the string to a list using ast.literal_eval
|
||||
list_obj = ast.literal_eval(list_str)
|
||||
# Check if list_obj is actually a list
|
||||
if not isinstance(list_obj, list):
|
||||
return list_str
|
||||
# If the list has one element, return that element
|
||||
if len(list_obj) == 1:
|
||||
return list_obj[0]
|
||||
# Otherwise, return the list as a string
|
||||
return ", ".join(list_obj)
|
||||
except (ValueError, SyntaxError):
|
||||
return list_str
|
||||
|
||||
@@ -40,6 +40,7 @@ class TestPostprocessFunctions(unittest.TestCase):
|
||||
def test_flatten_singleton_string_list(self):
|
||||
self.assertEqual(flatten_singleton_string_list("['123']"), "123")
|
||||
self.assertEqual(flatten_singleton_string_list("['123', '456']"), "123, 456")
|
||||
self.assertEqual(flatten_singleton_string_list("11"), "11")
|
||||
self.assertEqual(flatten_singleton_string_list("invalid"), "invalid")
|
||||
self.assertEqual(flatten_singleton_string_list(None), "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user