-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.5
pydantic compiled: True
python version: 3.7.5 (default, Nov 7 2019, 10:50:52) [GCC 8.3.0]
platform: Linux-4.4.0-18362-Microsoft-x86_64-with-Ubuntu-18.04-bionic
optional deps. installed: ['typing-extensions']
Example code:
import math
from pydantic import BaseModel, Field
class MyModel(BaseModel):
myfloat: float = Field(..., lt=math.inf)
print(MyModel.schema())
# {'title': 'MyModel', 'type': 'object', 'properties': {'myfloat': {'title': 'Myfloat', 'exclusiveMaximum': inf, 'type': 'number'}}, 'required': ['myfloat']}The inf is not json-compliant:
{
"properties": {
"myfloat": {
"exclusiveMaximum": inf,
"title": "Myfloat"
5D5A
,
"type": "number"
}
},
"required": [
"myfloat"
],
"title": "MyModel",
"type": "object"
}However, json-compliant strings cannot include inf anyway, so the presence of 'exclusiveMaximum': inf (or conversely, 'exclusiveMinimum': -inf) in the schema seems to be a bug.
Note that the reason that I have lt=math.inf in the first place is because I am trying to limit myfloat to real-valued floats. Perhaps pydantic provides a better way to do this?
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X