hgrecco/pint — pull request #140 by jdreaver (2014-05-13 00:23:58+00:00)
Title: Fix bug where conversion would fail b/c of caching

I was experiencing an annoying error where repeated calls of ``ureg.convert`` would fail because the ``lru_cache`` on ``ParserHelper.from_string`` would return the already-modified object from the previous conversion:

```python
>>> ureg.convert(1, "m", "ft")
3.280839895013123

>>> ureg.convert(1, "m", "ft")
---------------------------------------------------------------------------
DimensionalityError Traceback (most recent call last)
in ()
----> 1 ureg.convert(1, "m", "ft")

/home/david/Dropbox/.virtualenvs/frackoptima/lib/python3.4/site-packages/pint/unit.py in convert(self, value, src,
dst, inplace)
995
996 if src_dim != dst_dim:
--> 997 raise DimensionalityError(src, dst, src_dim, dst_dim)
998
999 if len(src) == 1:

DimensionalityError: Cannot convert from '1.0 {'ft': -1.0, 'm': 1.0}' (dimensionless) to '1 {'ft': 1.0}' ([length])
```

I tried making the ``ParserHelper.from_string`` function always return a copy by doing something like this:

```python
@classmethod
def from_string(cls, input_string):
return cls.cached_from_string(input_string).copy()
# Note that pull request defined ParserHelper.copy()

@classmethod
@lru_cache()
def cached_from_string(cls, input_string):
# Contents of old from_string function
...

```

However, this caused a recursion limit error when loading the definitions file. For a quick fix, I just slapped ``copy()`` calls on the ``from_string`` calls inside the convert function only.

I also added a test that reproduced the bug.