diff --git a/spacy/matcher/matcher.pyx b/spacy/matcher/matcher.pyx index 37218ce0d..b58c0e072 100644 --- a/spacy/matcher/matcher.pyx +++ b/spacy/matcher/matcher.pyx @@ -105,7 +105,7 @@ cdef class Matcher: raise ValueError(Errors.E012.format(key=key)) if self.validator: errors[i] = validate_json(pattern, self.validator) - if errors: + if any(err for err in errors.values()): raise MatchPatternError(key, errors) key = self._normalize_key(key) for pattern in patterns: diff --git a/spacy/tests/regression/test_issue3549.py b/spacy/tests/regression/test_issue3549.py new file mode 100644 index 000000000..3932bf19c --- /dev/null +++ b/spacy/tests/regression/test_issue3549.py @@ -0,0 +1,15 @@ +# coding: utf8 +from __future__ import unicode_literals + +import pytest +from spacy.matcher import Matcher +from spacy.errors import MatchPatternError + + +def test_issue3549(en_vocab): + """Test that match pattern validation doesn't raise on empty errors.""" + matcher = Matcher(en_vocab, validate=True) + pattern = [{"LOWER": "hello"}, {"LOWER": "world"}] + matcher.add("GOOD", None, pattern) + with pytest.raises(MatchPatternError): + matcher.add("BAD", None, [{"X": "Y"}])