File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 44
55from __future__ import annotations
66
7+ import re
78import sys
8- from typing import Any
9+ from typing import Any , ClassVar , Pattern
910
1011
1112if sys .version_info [:2 ] >= (3 , 9 ):
@@ -74,6 +75,21 @@ class _RutPydanticAnnotation:
7475 b'"78773510-K"'
7576 """
7677
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+
7793 @classmethod
7894 def __get_pydantic_core_schema__ (
7995 cls , source_type : Any , handler : pydantic .GetCoreSchemaHandler
@@ -83,9 +99,7 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
8399
84100 from_str_schema = pydantic_core .core_schema .chain_schema (
85101 [
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 ),
89103 pydantic_core .core_schema .no_info_plain_validator_function (validate_from_str ),
90104 ]
91105 )
You can’t perform that action at this time.
0 commit comments