diff --git a/src/registry.py b/src/registry.py index ed1c77c0c..03acf88e3 100644 --- a/src/registry.py +++ b/src/registry.py @@ -785,6 +785,17 @@ class Regexp(Value): else: super().set(v) + def setValue(self, v): + """Don't call this function directly from plugins, it is subject + to change without notice.""" + if v is not None and (not isinstance(v, tuple) or len(v) != 2): + raise InvalidRegistryValue( + 'Can\'t setValue a regexp, there would be an inconsistency ' + 'between the regexp and the recorded string value. ' + 'Use .set() instead.') + + super().setValue(v) + def __call__(self): if self.value is None: return None diff --git a/test/test_registry.py b/test/test_registry.py index 956f3bfbd..7f48aa929 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -183,6 +183,13 @@ class ValuesTestCase(SupyTestCase): v.set('') self.assertEqual(v(), None) + def testRegexpSetValue(self): + v = registry.Regexp(None, 'help') + self.assertRaises(registry.InvalidRegistryValue, + v.setValue, r'foo') + self.assertRaises(registry.InvalidRegistryValue, + v.setValue, re.compile(r'foo')) + def testRegexpDefaultString(self): v = registry.Regexp('m/foo/', 'help') self.assertEqual(v(), re.compile('foo'))