Skip to content

Commit 82d1d4b

Browse files
authored
Merge pull request #272 from dapper91/fix/typing
- typing fix
2 parents 8c219ca + ec4b547 commit 82d1d4b

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

pydantic_xml/fields.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import dataclasses as dc
22
import typing
3-
from typing import Any, Callable, Optional, Type, TypeVar, Union
3+
from typing import Any, Callable, Optional, TypeVar, Union
44

55
import pydantic as pd
66
import pydantic_core as pdc
77
from pydantic._internal._model_construction import ModelMetaclass # noqa
88
from pydantic.root_model import _RootModelMetaclass as RootModelMetaclass # noqa
99

1010
from . import config, model, utils
11-
from .element import XmlElementReader, XmlElementWriter
1211
from .typedefs import EntityLocation
1312
from .utils import NsMap
1413

@@ -22,8 +21,6 @@
2221
'xml_field_serializer',
2322
'xml_field_validator',
2423
'ComputedXmlEntityInfo',
25-
'SerializerFunc',
26-
'ValidatorFunc',
2724
'XmlEntityInfo',
2825
'XmlEntityInfoP',
2926
'XmlFieldSerializer',
@@ -295,8 +292,7 @@ def computed_element(
295292
return computed_entity(EntityLocation.ELEMENT, prop, path=tag, ns=ns, nsmap=nsmap, nillable=nillable, **kwargs)
296293

297294

298-
ValidatorFunc = Callable[[Type['model.BaseXmlModel'], XmlElementReader, str], Any]
299-
ValidatorFuncT = TypeVar('ValidatorFuncT', bound=ValidatorFunc)
295+
ValidatorFuncT = TypeVar('ValidatorFuncT', bound='model.SerializerFunc')
300296

301297

302298
def xml_field_validator(field: str, /, *fields: str) -> Callable[[ValidatorFuncT], ValidatorFuncT]:
@@ -314,8 +310,7 @@ def wrapper(func: ValidatorFuncT) -> ValidatorFuncT:
314310
return wrapper
315311

316312

317-
SerializerFunc = Callable[['model.BaseXmlModel', XmlElementWriter, Any, str], Any]
318-
SerializerFuncT = TypeVar('SerializerFuncT', bound=SerializerFunc)
313+
SerializerFuncT = TypeVar('SerializerFuncT', bound='model.SerializerFunc')
319314

320315

321316
def xml_field_serializer(field: str, /, *fields: str) -> Callable[[SerializerFuncT], SerializerFuncT]:
@@ -335,9 +330,9 @@ def wrapper(func: SerializerFuncT) -> SerializerFuncT:
335330

336331
@dc.dataclass(frozen=True)
337332
class XmlFieldValidator:
338-
func: ValidatorFunc
333+
func: 'model.ValidatorFunc'
339334

340335

341336
@dc.dataclass(frozen=True)
342337
class XmlFieldSerializer:
343-
func: SerializerFunc
338+
func: 'model.SerializerFunc'

pydantic_xml/model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import typing
2-
from typing import Any, ClassVar, Dict, Generic, Optional, Tuple, Type, TypeVar, Union
2+
from typing import Any, Callable, ClassVar, Dict, Generic, Optional, Tuple, Type, TypeVar, Union
33

44
import pydantic as pd
55
import pydantic_core as pdc
@@ -9,10 +9,9 @@
99
from pydantic.root_model import _RootModelMetaclass as RootModelMetaclass # noqa
1010

1111
from . import config, errors, utils
12-
from .element import SearchMode
12+
from .element import SearchMode, XmlElementReader, XmlElementWriter
1313
from .element.native import ElementT, XmlElement, etree
14-
from .fields import SerializerFunc, ValidatorFunc, XmlEntityInfo, XmlFieldSerializer, XmlFieldValidator, attr, element
15-
from .fields import wrapped
14+
from .fields import XmlEntityInfo, XmlFieldSerializer, XmlFieldValidator, attr, element, wrapped
1615
from .serializers.factories.model import BaseModelSerializer
1716
from .serializers.serializer import Serializer
1817
from .typedefs import EntityLocation
@@ -22,6 +21,8 @@
2221
'BaseXmlModel',
2322
'create_model',
2423
'RootXmlModel',
24+
'SerializerFunc',
25+
'ValidatorFunc',
2526
'XmlModelMeta',
2627
)
2728

@@ -136,6 +137,8 @@ def _collect_xml_field_serializers_validators(mcls, cls: Type['BaseXmlModel']) -
136137
cls.__xml_field_validators__[field] = func
137138

138139

140+
ValidatorFunc = Callable[[Type['BaseXmlModel'], XmlElementReader, str], Any]
141+
SerializerFunc = Callable[['BaseXmlModel', XmlElementWriter, Any, str], Any]
139142
ModelT = TypeVar('ModelT', bound='BaseXmlModel')
140143

141144

0 commit comments

Comments
 (0)