uber / charlatan

A Python library to efficiently manage and install database fixtures
https://charlatan.readthedocs.org/en/latest/
Other
89 stars 12 forks source link

Fix anonymous list objects name resolution resolves #47 #48

Closed jvrsantacruz closed 9 years ago

jvrsantacruz commented 9 years ago

Generalized charlatan.utils.richgetter function to resolve object paths including dict, object and list.

It uses instance type comparision against standard collection ABC metaclasses.

>>> import collections
>>> isinstance(list(), collections.Sequence)
True
>>> isinstance(list(), collections.Mapping)
False
>>> isinstance(dict(), collections.Sequence)
False
>>> isinstance(dict(), collections.Mapping)
True
>>> isinstance(object(), collections.Sequence)
False
>>> isinstance(object(), collections.Mapping)
False

As in the tests, the spec object.values.0 should resolve to 'value' in this context:

>>> obj = Namespace(key=dict(values=['value'])))
>>> richgetter(obj, 'key.values.0')
'value'

Note that previous implementation would have resolved key.values to the dict.values() method instead of dict['values'] which is the correct thing to do.

This should fix #47 as it now handles list indexes correctly.

Thanks for such a nice library :)

charlax commented 9 years ago

Awesome! Thanks for the fix!

charlax commented 9 years ago

Released as 0.4.3.

jvrsantacruz commented 9 years ago

Perfect! It has been so fast I didn't even had to mock the version in my own pipyserver. Thanks you! On 26 May 2015 18:43, "Charles-Axel Dein" notifications@github.com wrote:

Released as 0.4.3.

— Reply to this email directly or view it on GitHub https://github.com/uber/charlatan/pull/48#issuecomment-105597954.

charlax commented 9 years ago

I know what it is to wait for the release to happen, so that's why I released it fast :)