Skip to content

Commit

Permalink
refactor(main): use ROOT_KEY instead of __root__
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Jan 12, 2021
1 parent 1be23a8 commit 202fe86
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pydantic/main.py
Expand Up @@ -195,7 +195,7 @@ def prepare_config(config: Type[BaseConfig], cls_name: str) -> None:

def validate_custom_root_type(fields: Dict[str, ModelField]) -> None:
if len(fields) > 1:
raise ValueError('__root__ cannot be mixed with other fields')
raise ValueError(f'{ROOT_KEY} cannot be mixed with other fields')


UNTOUCHED_TYPES = FunctionType, property, type, classmethod, staticmethod
Expand Down Expand Up @@ -569,7 +569,7 @@ def parse_file(
def from_orm(cls: Type['Model'], obj: Any) -> 'Model':
if not cls.__config__.orm_mode:
raise ConfigError('You must have the config attribute orm_mode=True to use from_orm')
obj = {'__root__': obj} if cls.__custom_root_type__ else cls._decompose_class(obj)
obj = {ROOT_KEY: obj} if cls.__custom_root_type__ else cls._decompose_class(obj)
m = cls.__new__(cls)
values, fields_set, validation_error = validate_model(cls, obj)
if validation_error:
Expand Down Expand Up @@ -705,8 +705,8 @@ def _get_value(
exclude=exclude,
exclude_none=exclude_none,
)
if '__root__' in v_dict:
return v_dict['__root__']
if ROOT_KEY in v_dict:
return v_dict[ROOT_KEY]
return v_dict
else:
return v.copy(include=include, exclude=exclude)
Expand Down

0 comments on commit 202fe86

Please sign in to comment.