joshmarshall/mogo — pull request #9 by jeffasnome (2012-01-01 19:39:47+00:00)
Title: cast fields to the right value_type

I'm porting snoball from nod's mogo to this mogo. Nod's fork of mogo did not do any validation of value_type, so we have a several fields that get assigned both floats and ints. I think it'd be good to still validate that it is a number.

If the isinstance check fails, this patch sends value to value_type's constructor. This does something reasonable for most built-in types: Field(list) will turn any iterable object into a list, Field(float) will turn ints into floats, and Field(unicode) will convert strs to unicode.