edx/XBlock — pull request #200 by FiloSottile (2014-04-04 23:04:47+00:00)
Title: Enforce type of the Fields when set

Add a `enforce_type` method and call it on `__set__` to make sure that the stored value type is consistent.

Calling simply `from_json` instead of `enforce_type` would be tempting, however `from_json` is a heavily subclassed public method that might NOT expect the proper type of the field. Look at `DateTime`, `from_json` would error out on a `datetime.datetime`.

The most clean way to do this would be to rename `from_json` and call it, but I assumed I would break code I can't see if I had done it.

---

edx-solutions/xblock-mentoring#12 and edx-solutions/xblock-mentoring#11 depend on this.

Pinging @antoviaque and @aboudreault