diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index 3c086cb9..c94691a5 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -124,7 +124,7 @@ CONFIG_REPO_DICT = schema.Map( schema.Conditional( 'sha', schema.check_string, condition_key='repo', - condition_value=schema.NotIn((_LOCAL_SENTINEL, _META_SENTINEL)), + condition_value=schema.NotIn(_LOCAL_SENTINEL, _META_SENTINEL), ensure_absent=True, ), ) diff --git a/pre_commit/schema.py b/pre_commit/schema.py index e85c2303..89e1bcfc 100644 --- a/pre_commit/schema.py +++ b/pre_commit/schema.py @@ -201,17 +201,14 @@ class Array(collections.namedtuple('Array', ('of',))): return [remove_defaults(val, self.of) for val in v] -class Not(object): - def __init__(self, val): - self.val = val - +class Not(collections.namedtuple('Not', ('val',))): def __eq__(self, other): return other is not MISSING and other != self.val -class NotIn(object): - def __init__(self, values): - self.values = values +class NotIn(collections.namedtuple('NotIn', ('values',))): + def __new__(cls, *values): + return super(NotIn, cls).__new__(cls, values=values) def __eq__(self, other): return other is not MISSING and other not in self.values diff --git a/tests/schema_test.py b/tests/schema_test.py index 06f28e76..565f7e17 100644 --- a/tests/schema_test.py +++ b/tests/schema_test.py @@ -113,7 +113,7 @@ def test_not(val, expected): (('bar', True), ('foo', False), (MISSING, False)), ) def test_not_in(values, expected): - compared = NotIn(('baz', 'foo')) + compared = NotIn('baz', 'foo') assert (values == compared) is expected assert (compared == values) is expected @@ -211,7 +211,7 @@ map_conditional_absent_not_in = Map( 'foo', 'key', Conditional( 'key2', check_bool, - condition_key='key', condition_value=NotIn((1, 2)), ensure_absent=True, + condition_key='key', condition_value=NotIn(1, 2), ensure_absent=True, ), )