From 60c2c3555e867be17b95431274d9809d7fb2b2b9 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 22 Nov 2023 09:23:05 +0000 Subject: [PATCH] tweak tests and comment --- src/validators/literal.rs | 6 +++--- tests/validators/test_union.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/validators/literal.rs b/src/validators/literal.rs index d71a0ac2a..9f8c25e0f 100644 --- a/src/validators/literal.rs +++ b/src/validators/literal.rs @@ -136,9 +136,9 @@ impl LiteralLookup { } // must be an enum or bytes if let Some(expected_py) = &self.expected_py { - // We don't use ? to unpack the result of get_item in the next line because unhashable - // inputs will produce a TypeError, which in this case we just want to treat as a - // validation failure + // We don't use ? to unpack the result of `get_item` in the next line because unhashable + // inputs will produce a TypeError, which in this case we just want to treat equivalently + // to a failed lookup if let Ok(Some(v)) = expected_py.as_ref(py).get_item(input) { let id: usize = v.extract().unwrap(); return Ok(Some((input, &self.values[id]))); diff --git a/tests/validators/test_union.py b/tests/validators/test_union.py index 3a1884f3f..42c542000 100644 --- a/tests/validators/test_union.py +++ b/tests/validators/test_union.py @@ -799,5 +799,7 @@ class ModelA: # validation against Literal[True] fails bc of the unhashable dict # A ValidationError is raised, not a ValueError, which allows the validation against the union to continue - assert validator.validate_python({'a': 42}) - assert validator.validate_python(True) + m = validator.validate_python({'a': 42}) + assert isinstance(m, ModelA) + assert m.a == 42 + assert validator.validate_python(True) is True