|
1 | 1 | import dataclasses as dc
|
2 | 2 | import typing
|
3 |
| -from typing import Any, Callable, Optional, TypeVar, Union |
| 3 | +from typing import Any, Callable, Optional, Union |
4 | 4 |
|
5 | 5 | import pydantic as pd
|
6 | 6 | import pydantic_core as pdc
|
@@ -292,36 +292,38 @@ def computed_element(
|
292 | 292 | return computed_entity(EntityLocation.ELEMENT, prop, path=tag, ns=ns, nsmap=nsmap, nillable=nillable, **kwargs)
|
293 | 293 |
|
294 | 294 |
|
295 |
| -ValidatorFuncT = TypeVar('ValidatorFuncT', bound='model.SerializerFunc') |
296 |
| - |
297 |
| - |
298 |
| -def xml_field_validator(field: str, /, *fields: str) -> Callable[[ValidatorFuncT], ValidatorFuncT]: |
| 295 | +def xml_field_validator( |
| 296 | + field: str, /, *fields: str |
| 297 | +) -> 'Callable[[model.ValidatorFuncT[model.ModelT]], model.ValidatorFuncT[model.ModelT]]': |
299 | 298 | """
|
300 | 299 | Marks the method as a field xml validator.
|
301 | 300 |
|
302 | 301 | :param field: field to be validated
|
303 | 302 | :param fields: fields to be validated
|
304 | 303 | """
|
305 | 304 |
|
306 |
| - def wrapper(func: ValidatorFuncT) -> ValidatorFuncT: |
| 305 | + def wrapper(func: model.ValidatorFuncT[model.ModelT]) -> model.ValidatorFuncT[model.ModelT]: |
| 306 | + if isinstance(func, (classmethod, staticmethod)): |
| 307 | + func = func.__func__ |
307 | 308 | setattr(func, '__xml_field_validator__', (field, *fields))
|
308 | 309 | return func
|
309 | 310 |
|
310 | 311 | return wrapper
|
311 | 312 |
|
312 | 313 |
|
313 |
| -SerializerFuncT = TypeVar('SerializerFuncT', bound='model.SerializerFunc') |
314 |
| - |
315 |
| - |
316 |
| -def xml_field_serializer(field: str, /, *fields: str) -> Callable[[SerializerFuncT], SerializerFuncT]: |
| 314 | +def xml_field_serializer( |
| 315 | + field: str, /, *fields: str |
| 316 | +) -> 'Callable[[model.SerializerFuncT[model.ModelT]], model.SerializerFuncT[model.ModelT]]': |
317 | 317 | """
|
318 | 318 | Marks the method as a field xml serializer.
|
319 | 319 |
|
320 | 320 | :param field: field to be serialized
|
321 | 321 | :param fields: fields to be serialized
|
322 | 322 | """
|
323 | 323 |
|
324 |
| - def wrapper(func: SerializerFuncT) -> SerializerFuncT: |
| 324 | + def wrapper(func: model.SerializerFuncT[model.ModelT]) -> model.SerializerFuncT[model.ModelT]: |
| 325 | + if isinstance(func, (classmethod, staticmethod)): |
| 326 | + func = func.__func__ |
325 | 327 | setattr(func, '__xml_field_serializer__', (field, *fields))
|
326 | 328 | return func
|
327 | 329 |
|
|
0 commit comments