diff --git a/pydantic/__init__.py b/pydantic/__init__.py index dcbc355d1fd..4fdba0824a9 100644 --- a/pydantic/__init__.py +++ b/pydantic/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa from . import dataclasses -from .annotated_types import namedtuple_to_model, typeddict_to_model +from .annotated_types import create_model_from_namedtuple, create_model_from_typeddict from .class_validators import root_validator, validator from .decorator import validate_arguments from .env_settings import BaseSettings @@ -18,8 +18,8 @@ # please use "from pydantic.errors import ..." instead __all__ = [ # annotated types utils - 'namedtuple_to_model', - 'typeddict_to_model', + 'create_model_from_namedtuple', + 'create_model_from_typeddict', # dataclasses 'dataclasses', # class_validators diff --git a/pydantic/annotated_types.py b/pydantic/annotated_types.py index 35ee5bce734..12d8b62166b 100644 --- a/pydantic/annotated_types.py +++ b/pydantic/annotated_types.py @@ -12,7 +12,7 @@ class TypedDict(Dict[str, Any]): __optional_keys__: FrozenSet[str] -def typeddict_to_model( +def create_model_from_typeddict( typeddict_cls: Type['TypedDict'], *, config: Optional[Type['BaseConfig']] = None ) -> Type['BaseModel']: """ @@ -45,7 +45,7 @@ def typeddict_to_model( return create_model(f'{typeddict_cls.__name__}Model', __config__=config, **field_definitions) -def namedtuple_to_model(namedtuple_cls: Type['NamedTuple']) -> Type['BaseModel']: +def create_model_from_namedtuple(namedtuple_cls: Type['NamedTuple']) -> Type['BaseModel']: """ Convert a named tuple to a `BaseModel` A named tuple can be created with `typing.NamedTuple` and declared annotations diff --git a/pydantic/validators.py b/pydantic/validators.py index 75b3941f1bd..193f66b6d93 100644 --- a/pydantic/validators.py +++ b/pydantic/validators.py @@ -544,9 +544,9 @@ def pattern_validator(v: Any) -> Pattern[str]: def make_named_tuple_validator(namedtuple_cls: Type[NamedTupleT]) -> Callable[[Tuple[Any, ...]], NamedTupleT]: - from .annotated_types import namedtuple_to_model + from .annotated_types import create_model_from_namedtuple - NamedTupleModel = namedtuple_to_model(namedtuple_cls) + NamedTupleModel = create_model_from_namedtuple(namedtuple_cls) def named_tuple_validator(values: Tuple[Any, ...]) -> NamedTupleT: dict_values: Dict[str, Any] = dict(zip(NamedTupleModel.__annotations__, values)) @@ -559,9 +559,9 @@ def named_tuple_validator(values: Tuple[Any, ...]) -> NamedTupleT: def make_typeddict_validator( typeddict_cls: Type['TypedDict'], config: Type['BaseConfig'] ) -> Callable[[Any], Dict[str, Any]]: - from .annotated_types import typeddict_to_model + from .annotated_types import create_model_from_typeddict - TypedDictModel = typeddict_to_model(typeddict_cls, config=config) + TypedDictModel = create_model_from_typeddict(typeddict_cls, config=config) def typeddict_validator(values: 'TypedDict') -> Dict[str, Any]: return TypedDictModel(**values).dict(exclude_unset=True)