Skip to content

Commit 36c7150

Browse files
authored
raise TypeError if input is not list of str for convert_list_to_comma_separated_string converter (#2154)
* raise typeerror if input is not list of str * allow tuple iterable along with list
1 parent 35ae011 commit 36c7150

14 files changed

Lines changed: 60 additions & 24 deletions

File tree

build/templates/_converters.py.mako

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
339339

340340

341341
def convert_list_to_comma_separated_string(list_of_strings):
342-
'''Convert a list of strings into a comma-separated string.
342+
'''Convert a list or tuple of strings into a comma-separated string.
343343

344344
Args:
345-
list_of_strings (list[str]): List of strings.
345+
list_of_strings (list or tuple of str): List or tuple of strings.
346346

347347
Returns:
348348
str: Comma-separated string.
349349
'''
350+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
351+
raise TypeError('Input must be a list or tuple of str')
350352
return ','.join(list_of_strings)
351353

352354

generated/nidcpower/nidcpower/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
330330

331331

332332
def convert_list_to_comma_separated_string(list_of_strings):
333-
'''Convert a list of strings into a comma-separated string.
333+
'''Convert a list or tuple of strings into a comma-separated string.
334334
335335
Args:
336-
list_of_strings (list[str]): List of strings.
336+
list_of_strings (list or tuple of str): List or tuple of strings.
337337
338338
Returns:
339339
str: Comma-separated string.
340340
'''
341+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
342+
raise TypeError('Input must be a list or tuple of str')
341343
return ','.join(list_of_strings)
342344

343345

generated/nidigital/nidigital/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

generated/nidmm/nidmm/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

generated/nifake/nifake/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
330330

331331

332332
def convert_list_to_comma_separated_string(list_of_strings):
333-
'''Convert a list of strings into a comma-separated string.
333+
'''Convert a list or tuple of strings into a comma-separated string.
334334
335335
Args:
336-
list_of_strings (list[str]): List of strings.
336+
list_of_strings (list or tuple of str): List or tuple of strings.
337337
338338
Returns:
339339
str: Comma-separated string.
340340
'''
341+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
342+
raise TypeError('Input must be a list or tuple of str')
341343
return ','.join(list_of_strings)
342344

343345

generated/nifake/nifake/unit_tests/test_converters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,9 @@ def test_convert_comma_separated_string_to_list():
413413
def test_convert_list_to_comma_separated_string():
414414
out_string = _converters.convert_list_to_comma_separated_string(['PinA', 'PinB', 'PinC'])
415415
assert out_string == 'PinA,PinB,PinC'
416+
417+
418+
def test_convert_list_to_comma_separated_string_invalid_input():
419+
with pytest.raises(TypeError) as error_info:
420+
_converters.convert_list_to_comma_separated_string('PinA,PinB,PinC')
421+
assert str(error_info.value) == 'Input must be a list or tuple of str'

generated/nifgen/nifgen/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

generated/nimodinst/nimodinst/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

generated/nirfsg/nirfsg/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

generated/niscope/niscope/_converters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,16 @@ def convert_comma_separated_string_to_list(comma_separated_string):
329329

330330

331331
def convert_list_to_comma_separated_string(list_of_strings):
332-
'''Convert a list of strings into a comma-separated string.
332+
'''Convert a list or tuple of strings into a comma-separated string.
333333
334334
Args:
335-
list_of_strings (list[str]): List of strings.
335+
list_of_strings (list or tuple of str): List or tuple of strings.
336336
337337
Returns:
338338
str: Comma-separated string.
339339
'''
340+
if not isinstance(list_of_strings, (list, tuple)) or not all(isinstance(item, str) for item in list_of_strings):
341+
raise TypeError('Input must be a list or tuple of str')
340342
return ','.join(list_of_strings)
341343

342344

0 commit comments

Comments
 (0)