jazzband / jsonmodels

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.
http://jsonmodels.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
334 stars 51 forks source link

Add parsing to IntField #89

Closed omeranson closed 6 years ago

omeranson commented 6 years ago

Having IntField parse its input allows a field of this type to be assigned by a textual representation of a string or (in python 2) a long.

This allows data sources which mix ints and longs, or ints and their representation, to provide legal values to JSON models.

omeranson commented 6 years ago

@beregond Could you take a look at this?

dimakuz commented 6 years ago

I don't think we should add such an implicit coercion, most python code does not define such semantics, and python folks tend to move away it.

https://docs.python.org/2.5/ref/coercion-rules.html

beregond commented 6 years ago

You have point @dimakuz but on the other hand there are other examples when what you get is not what you give, like in datetime fields. I think as long as the inner representation is proper (as int) and we only filter noise that may come from 3rd party sources - we should be ok and this will make life easier for developers (otherwise you would have to write your own field anyway). What do you think, @dimakuz ?

dimakuz commented 6 years ago

@beregond I agree, if we can cast datetime from string, lets allow this for integers as well

beregond commented 6 years ago

Released in 2.3 - thanks!