diff --git a/protovalidate/internal/rules.py b/protovalidate/internal/rules.py index b4d995a3..8ce6975f 100644 --- a/protovalidate/internal/rules.py +++ b/protovalidate/internal/rules.py @@ -267,11 +267,9 @@ class RuleContext: _violations: list[Violation] - def __init__(self, *, fail_fast: bool = False, violations: typing.Optional[list[Violation]] = None): + def __init__(self, *, fail_fast: bool = False): self._fail_fast = fail_fast - if violations is None: - violations = [] - self._violations = violations + self._violations = [] @property def violations(self) -> list[Violation]: diff --git a/protovalidate/validator.py b/protovalidate/validator.py index 443e08ff..28b3d9be 100644 --- a/protovalidate/validator.py +++ b/protovalidate/validator.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import typing - from google.protobuf import message from buf.validate import validate_pb2 @@ -63,7 +61,6 @@ def collect_violations( message: message.Message, *, fail_fast: bool = False, - into: typing.Optional[list[Violation]] = None, ) -> list[Violation]: """ Validates the given message against the static rules defined in @@ -77,12 +74,10 @@ def collect_violations( Parameters: message: The message to validate. fail_fast: If true, validation will stop after the first iteration. - into: If provided, any violations will be appended to the - Violations object and the same object will be returned. Raises: CompilationError: If the static rules could not be compiled. """ - ctx = _rules.RuleContext(fail_fast=fail_fast, violations=into) + ctx = _rules.RuleContext(fail_fast=fail_fast) for rule in self._factory.get(message.DESCRIPTOR): rule.validate(ctx, message) if ctx.done: diff --git a/test/test_validate.py b/test/test_validate.py index b7ea1036..c0589692 100644 --- a/test/test_validate.py +++ b/test/test_validate.py @@ -85,20 +85,6 @@ def test_oneofs(self): self._run_valid_tests(msg) - def test_collect_violations_into(self): - msg1 = validations_pb2.Oneof() - msg1.y = 123 - - msg2 = validations_pb2.Oneof() - msg2.z.val = True - - for label, v in get_default_validator(): - with self.subTest(label=label): - # Test collect_violations into - violations = v.collect_violations(msg1) - v.collect_violations(msg2, into=violations) - self.assertEqual(len(violations), 0) - def test_protovalidate_oneof_valid(self): msg = validations_pb2.ProtovalidateOneof() msg.a = "A"