pydantic-core icon indicating copy to clipboard operation
pydantic-core copied to clipboard

stop bytes being converted to `int` and `float`

Open samuelcolvin opened this issue 3 years ago • 3 comments

stop using maybe_as_string.

samuelcolvin avatar Jul 06 '22 16:07 samuelcolvin

Just a quick question: So you want to make "coerce" mode a bit stricter right? And for pydantic v2 what is your plan?

  • update the doc and say that people should add custom validator to coerce to string if they want?
  • add it directly in pydantic v2 behind a flag/config param?

PrettyWood avatar Jul 06 '22 16:07 PrettyWood

Maybe, I want to avoid config flags if possible but some might be necessary.

See what others say.

samuelcolvin avatar Jul 06 '22 20:07 samuelcolvin

Humm, I'm not sure about this anymore.

There are two fairly intuitive representations of b'123' as an int:

b = b'123'
assert int(b) == 123
assert int.from_bytes(b, 'big') == 3224115

I can imagine the vast majority of users would expect the first option to work (as it does now).

Let's leave this for now.

samuelcolvin avatar Aug 02 '22 13:08 samuelcolvin