Skip to content

Commit 2415f42

Browse files
authored
uuid: allow str subclass as input (#1296)
1 parent f04418b commit 2415f42

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/validators/uuid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::errors::{ErrorType, ErrorTypeDefaults, ValError, ValResult};
1212
use crate::input::input_as_python_instance;
1313
use crate::input::Input;
1414
use crate::input::InputType;
15+
use crate::input::ValidationMatch;
1516
use crate::tools::SchemaDict;
1617

1718
use super::model::create_class;
@@ -152,7 +153,7 @@ impl Validator for UuidValidator {
152153

153154
impl UuidValidator {
154155
fn get_uuid<'py>(&self, input: &(impl Input<'py> + ?Sized)) -> ValResult<Uuid> {
155-
let uuid = match input.exact_str().ok() {
156+
let uuid = match input.validate_str(true, false).ok().map(ValidationMatch::into_inner) {
156157
Some(either_string) => {
157158
let cow = either_string.as_cow()?;
158159
let uuid_str = cow.as_ref();

tests/validators/test_uuid.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from ..conftest import Err, PyAndJson
1010

1111

12+
class MyStr(str): ...
13+
14+
1215
@pytest.mark.parametrize(
1316
'input_value,expected',
1417
[
@@ -25,6 +28,7 @@
2528
('c0a8f9a8-aa5e-482b-a067-9cb3a51f5c11', UUID('c0a8f9a8-aa5e-482b-a067-9cb3a51f5c11')),
2629
('00000000-8000-4000-8000-000000000000', UUID('00000000-8000-4000-8000-000000000000')),
2730
('00000000-0000-4000-0000-000000000000', UUID('00000000-0000-4000-0000-000000000000')),
31+
(MyStr('00000000-0000-4000-0000-000000000000'), UUID('00000000-0000-4000-0000-000000000000')),
2832
(b'\x12\x34\x56\x78' * 4, UUID('12345678-1234-5678-1234-567812345678')),
2933
(b'\x00\x00\x00\x00' * 4, UUID('00000000-0000-0000-0000-000000000000')),
3034
(b'ebcdab58-6eb8-46fb-a190-d07a33e9eac8', UUID('ebcdab58-6eb8-46fb-a190-d07a33e9eac8')),

0 commit comments

Comments
 (0)