!!! warning "Discouraged" This function is **discouraged** in favor of using [`Annotated`](https://docs.python.org/3/library/typing.html#typing.Annotated) with [`Field`][pydantic.fields.Field] instead. This function will be **deprecated** in Pydantic 3.0.
(
*,
strict: bool | None = None,
gt: int | Decimal | None = None,
ge: int | Decimal | None = None,
lt: int | Decimal | None = None,
le: int | Decimal | None = None,
multiple_of: int | Decimal | None = None,
max_digits: int | None = None,
decimal_places: int | None = None,
allow_inf_nan: bool | None = None,
)
| 1044 | |
| 1045 | |
| 1046 | def condecimal( |
| 1047 | *, |
| 1048 | strict: bool | None = None, |
| 1049 | gt: int | Decimal | None = None, |
| 1050 | ge: int | Decimal | None = None, |
| 1051 | lt: int | Decimal | None = None, |
| 1052 | le: int | Decimal | None = None, |
| 1053 | multiple_of: int | Decimal | None = None, |
| 1054 | max_digits: int | None = None, |
| 1055 | decimal_places: int | None = None, |
| 1056 | allow_inf_nan: bool | None = None, |
| 1057 | ) -> type[Decimal]: |
| 1058 | """ |
| 1059 | !!! warning "Discouraged" |
| 1060 | This function is **discouraged** in favor of using |
| 1061 | [`Annotated`](https://docs.python.org/3/library/typing.html#typing.Annotated) with |
| 1062 | [`Field`][pydantic.fields.Field] instead. |
| 1063 | |
| 1064 | This function will be **deprecated** in Pydantic 3.0. |
| 1065 | |
| 1066 | The reason is that `condecimal` returns a type, which doesn't play well with static analysis tools. |
| 1067 | |
| 1068 | === ":x: Don't do this" |
| 1069 | ```python |
| 1070 | from pydantic import BaseModel, condecimal |
| 1071 | |
| 1072 | class Foo(BaseModel): |
| 1073 | bar: condecimal(strict=True, allow_inf_nan=True) |
| 1074 | ``` |
| 1075 | |
| 1076 | === ":white_check_mark: Do this" |
| 1077 | ```python |
| 1078 | from decimal import Decimal |
| 1079 | from typing import Annotated |
| 1080 | |
| 1081 | from pydantic import BaseModel, Field |
| 1082 | |
| 1083 | class Foo(BaseModel): |
| 1084 | bar: Annotated[Decimal, Field(strict=True, allow_inf_nan=True)] |
| 1085 | ``` |
| 1086 | |
| 1087 | A wrapper around Decimal that adds validation. |
| 1088 | |
| 1089 | Args: |
| 1090 | strict: Whether to validate the value in strict mode. Defaults to `None`. |
| 1091 | gt: The value must be greater than this. Defaults to `None`. |
| 1092 | ge: The value must be greater than or equal to this. Defaults to `None`. |
| 1093 | lt: The value must be less than this. Defaults to `None`. |
| 1094 | le: The value must be less than or equal to this. Defaults to `None`. |
| 1095 | multiple_of: The value must be a multiple of this. Defaults to `None`. |
| 1096 | max_digits: The maximum number of digits. Defaults to `None`. |
| 1097 | decimal_places: The number of decimal places. Defaults to `None`. |
| 1098 | allow_inf_nan: Whether to allow infinity and NaN. Defaults to `None`. |
| 1099 | |
| 1100 | ```python |
| 1101 | from decimal import Decimal |
| 1102 | |
| 1103 | from pydantic import BaseModel, ValidationError, condecimal |
no test coverage detected