From 67ea7c8ee19cd97517b1aab1e7a939ebfa3d5aa8 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 22 Mar 2018 12:11:28 +0000 Subject: [PATCH] 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. --- wa/utils/types.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wa/utils/types.py b/wa/utils/types.py index 8ede60da..607c5a84 100644 --- a/wa/utils/types.py +++ b/wa/utils/types.py @@ -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)