Coverage for /pythoncovmergedfiles/medio/medio/src/pydantic/pydantic/config.py: 100%

42 statements  

« prev     ^ index     » next       coverage.py v7.2.3, created at 2023-04-27 07:38 +0000

1"""Configuration for Pydantic models.""" 

2from __future__ import annotations as _annotations 

3 

4from typing import Any, Callable 

5from warnings import warn 

6 

7from typing_extensions import Literal, TypedDict 

8 

9from ._migration import getattr_migration 

10from .deprecated.config import BaseConfig 

11 

12__all__ = 'BaseConfig', 'ConfigDict', 'Extra' 

13 

14 

15class _Extra: 

16 allow: Literal['allow'] = 'allow' 

17 ignore: Literal['ignore'] = 'ignore' 

18 forbid: Literal['forbid'] = 'forbid' 

19 

20 def __getattribute__(self, __name: str) -> Any: 

21 warn( 

22 '`pydantic.config.Extra` is deprecated, use literal values instead' " (e.g. `extra='allow'`)", 

23 DeprecationWarning, 

24 stacklevel=2, 

25 ) 

26 return super().__getattribute__(__name) 

27 

28 

29Extra = _Extra() 

30 

31ExtraValues = Literal['allow', 'ignore', 'forbid'] 

32 

33 

34class ConfigDict(TypedDict, total=False): 

35 """A dictionary-like class for configuring Pydantic models. 

36 

37 Attributes: 

38 title (Optional[str]): Optional title for the configuration. Defaults to None. 

39 str_to_lower (bool): Whether to convert strings to lowercase. Defaults to False. 

40 str_to_upper (bool): Whether to convert strings to uppercase. Defaults to False. 

41 str_strip_whitespace (bool): Whether to strip whitespace from strings. Defaults to False. 

42 str_min_length (int): The minimum length for strings. Defaults to None. 

43 str_max_length (int): The maximum length for strings. Defaults to None. 

44 extra (ExtraValues): Extra values to include in this configuration. Defaults to None. 

45 frozen (bool): Whether to freeze the configuration. Defaults to False. 

46 populate_by_name (bool): Whether to populate fields by name. Defaults to False. 

47 use_enum_values (bool): Whether to use enum values. Defaults to False. 

48 validate_assignment (bool): Whether to validate assignments. Defaults to False. 

49 arbitrary_types_allowed (bool): Whether to allow arbitrary types. Defaults to True. 

50 undefined_types_warning (bool): Whether to show a warning for undefined types. Defaults to True. 

51 from_attributes (bool): Whether to set attributes from the configuration. Defaults to False. 

52 loc_by_alias (bool): Whether to use the alias for error `loc`s. Defaults to True. 

53 alias_generator (Optional[Callable[[str], str]]): A function to generate aliases. Defaults to None. 

54 ignored_types (Tuple[type, ...]): A tuple of types to ignore. Defaults to (). 

55 allow_inf_nan (bool): Whether to allow infinity and NaN. Defaults to False. 

56 strict (bool): Whether to make the configuration strict. Defaults to False. 

57 revalidate_instances (Literal['always', 'never', 'subclass-instances']): 

58 When and how to revalidate models and dataclasses during validation. Defaults to 'never'. 

59 ser_json_timedelta (Literal['iso8601', 'float']): The format of JSON serialized timedeltas. 

60 Defaults to 'iso8601'. 

61 ser_json_bytes (Literal['utf8', 'base64']): The encoding of JSON serialized bytes. Defaults to 'utf8'. 

62 validate_default (bool): Whether to validate default values during validation. Defaults to False. 

63 """ 

64 

65 title: str | None 

66 str_to_lower: bool 

67 str_to_upper: bool 

68 str_strip_whitespace: bool 

69 str_min_length: int 

70 str_max_length: int | None 

71 extra: ExtraValues | None 

72 frozen: bool 

73 populate_by_name: bool 

74 use_enum_values: bool 

75 validate_assignment: bool 

76 arbitrary_types_allowed: bool # TODO default True, or remove 

77 undefined_types_warning: bool # TODO review docs 

78 from_attributes: bool 

79 # whether to use the used alias (or first alias for "field required" errors) instead of field_names 

80 # to construct error `loc`s, default True 

81 loc_by_alias: bool 

82 alias_generator: Callable[[str], str] | None 

83 ignored_types: tuple[type, ...] 

84 allow_inf_nan: bool 

85 

86 # new in V2 

87 strict: bool 

88 # whether instances of models and dataclasses (including subclass instances) should re-validate, default 'never' 

89 revalidate_instances: Literal['always', 'never', 'subclass-instances'] 

90 ser_json_timedelta: Literal['iso8601', 'float'] 

91 ser_json_bytes: Literal['utf8', 'base64'] 

92 # whether to validate default values during validation, default False 

93 validate_default: bool 

94 # whether to validate the return value from call validator 

95 validate_return: bool 

96 

97 

98__getattr__ = getattr_migration(__name__)