File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from __future__ import annotations
6
6
7
+ import re
7
8
import sys
8
- from typing import Any
9
+ from typing import Any , ClassVar , Pattern
9
10
10
11
11
12
if sys .version_info [:2 ] >= (3 , 9 ):
@@ -74,6 +75,21 @@ class _RutPydanticAnnotation:
74
75
b'"78773510-K"'
75
76
"""
76
77
78
+ RUT_CANONICAL_STRICT_REGEX : ClassVar [Pattern ] = re .compile (
79
+ re .sub (
80
+ pattern = r'\?P<\w+>' ,
81
+ repl = '' ,
82
+ string = cl_sii .rut .constants .RUT_CANONICAL_STRICT_REGEX .pattern ,
83
+ )
84
+ )
85
+ """
86
+ RUT (strict) regex for canonical format, without named groups.
87
+
88
+ .. warning::
89
+ JSON Schema and OpenAPI use the regular expression syntax from
90
+ JavaScript (ECMA 262), which does not support Python’s named groups.
91
+ """
92
+
77
93
@classmethod
78
94
def __get_pydantic_core_schema__ (
79
95
cls , source_type : Any , handler : pydantic .GetCoreSchemaHandler
@@ -83,9 +99,7 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
83
99
84
100
from_str_schema = pydantic_core .core_schema .chain_schema (
85
101
[
86
- pydantic_core .core_schema .str_schema (
87
- pattern = cl_sii .rut .constants .RUT_CANONICAL_STRICT_REGEX .pattern
88
- ),
102
+ pydantic_core .core_schema .str_schema (pattern = cls .RUT_CANONICAL_STRICT_REGEX ),
89
103
pydantic_core .core_schema .no_info_plain_validator_function (validate_from_str ),
90
104
]
91
105
)
You can’t perform that action at this time.
0 commit comments