i2mint / py2store

Tools to create simple and consistent interfaces to complicated and varied data sources.
MIT License
11 stars 2 forks source link

Delegating dunders, class makers, and pickles #85

Open thorwhalen opened 3 years ago

thorwhalen commented 3 years ago

In grub/base.py:

Since getattr deligation doesn't work with dunders, did this:

class SearchStoreMixin(KvReader):
    store_attr = 'search_store'

    def __getitem__(self, k):
        return getattr(self, self.store_attr).__getitem__(k)

    def __iter__(self):
        return getattr(self, self.store_attr).__iter__()

    def __contains__(self, k):
        return getattr(self, self.store_attr).__contains__(k)

    def __len__(self):
        return getattr(self, self.store_attr).__len__()

class StoreMixin(SearchStoreMixin):
    store_attr = 'store'

But surely, there's a more conciser way to do it.

I can make a function that makes classes, but will it pickle?