You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: importpydanticIn [2]: classA(pydantic.BaseModel):
...: i: int
...:
In [3]: A(i='4.0')
Out[3]: A(i=4)
In [4]: A(i='-4.0')
---------------------------------------------------------------------------ValidationErrorTraceback (mostrecentcalllast)
CellIn[4], line1---->1A(i='-4.0')
File~/.cache/pypoetry/virtualenvs/hl-7m4wOqun-py3.12/lib/python3.12/site-packages/pydantic/main.py:176, inBaseModel.__init__(self, **data)
174# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks175__tracebackhide__=True-->176self.__pydantic_validator__.validate_python(data, self_instance=self)
ValidationError: 1validationerrorforAiInputshouldbeavalidinteger, unabletoparsestringasaninteger [type=int_parsing, input_value='-4.0', input_type=str]
Forfurtherinformationvisithttps://errors.pydantic.dev/2.7/v/int_parsing
I investigated this and the issue seems to be in strip_leading_zeros function where if any character occurs except (+, _, 1 ... 9) in the string then None is being returned. The - character is not handled here and due to this it's throwing validation error.
Thanks for reporting this bug. Definitely something we want to fix in 2.7.2. Should be an easy fix if anyone is interested in contributing to pydantic-core. I'll pick this up soon if not!
Initial Checks
Description
Starting with pydantic 2.7.1 parsing an integer string like
'-1.0'
gives an error while'1.0'
works fine. Probably related to pydantic/pydantic-core#1269 or pydantic/pydantic-core#1272.Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: