def field(field_name, doc=None, read_only=False):
    """
    Map a dict field to a class property.

    Example usage:
    ```
    class Foo:
        bar = field("bar")
    ```
    is equivalent to

    ```
    class Foo:
        @property
        def bar(self):
            return self._data["bar"]

        @bar.setter
        def bar(self, value):
            self._data["bar"] = value
    ```
    """
    def getter(self):
        return self._data[field_name]

    if not read_only:
        def setter(self, value):
            self._data[field_name] = value

        return property(getter, setter, doc=doc)
    return property(getter, doc=doc)