lingpy/lingpy — pull request #119 by xrotwang (2014-11-08 19:48:01+00:00)
Title: pickle whole objects and make unpickling (i.e. loading from cache) explicit

Since my last PR refactoring the caching mechanism was buggy, I thought some more about this functionality. So here is my new proposal:

1. ``pickle`` is available for most python objects in general, not only ``dict``s. So just pickle the ``QLCParser`` instance and not just its ``dict`` of attributes. The only thing lost with this approach is the [extra timestamp](https://github.com/lingpy/lingpy/blob/master/lingpy/basic/parser.py#L272), but that is not really necessary, because it's available as ``ctime`` of the pickle file.

2. Make unpickling explicit. When looking at the code for the first time, I found the ``_init_first`` method awkward. Now I know why: This method is the real ``__init__`` -- loading the already initialized object from a pickle should be a simple factory function - so I turned this into a ``staticmethod`` of the class.

With this approach pickling and unpickling becomes a lot simpler and unpickling is something the user has to do consciously. But since this will only work if the user pickled the object consciously before, I think that is not a restriction, but rather follows the paradigm ["Explicit is better than implicit"](http://legacy.python.org/dev/peps/pep-0020/).