1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 20:11:20 +00:00

utils/types: toggle_set: TypeError on string

Strings are iterable, so can be used to instantiate sets (resulting in a
set of chars). This is never what we want for toggle_set's though, and
may result in difficult-to-interpret errors when parsing configuration,
so raise a TypeError if attempting to create a toggle_set with a string.
This commit is contained in:
Sergei Trofimov 2018-03-22 12:11:28 +00:00 committed by Marc Bonnici
parent 7464010677
commit 67ea7c8ee1

View File

@ -381,6 +381,14 @@ class toggle_set(set):
dest.add(item)
return dest
def __init__(self, *args):
if args:
value = args[0]
if isinstance(value, basestring):
msg = 'invalid type for toggle_set: "{}"'
raise TypeError(msg.format(type(value)))
set.__init__(self, *args)
def merge_with(self, other):
new_self = copy(self)
return toggle_set.merge(other, new_self)