Dynamically determine base classes on instantiation
Thomas Bach
thbach at students.uni-mainz.de
Thu Aug 16 12:54:12 EDT 2012
On Thu, Aug 16, 2012 at 05:10:43PM +0200, Hans Mulder wrote:
> On 16/08/12 14:52:30, Thomas Bach wrote:
> >
> > So, my question (as far as I can see it, please correct me if I am
> > wrong) is less of the "How do I achieve this?"-kind, but more of the
> > "What is a clean design for this?"-kind. My intuitive thought was that
> > the `merge' function should be a part of the object returned from `F'.
>
> The misunderstanding is that you feel F should return an object with
> a 'merge' method and a varying abse type, while Steven and others
> think that F should be a function.
OK, then my design wasn't so bad in the first place. :)
I made a class `Model' which wraps the actual type and realized
`merge' and `F' (with a better name, though) as classmethods of
`Model' in order to tie together the stuff that belongs together. By
the way, another need I saw for this design was that
setattr(Model(), 'foo', {'bar': int})
works, whereas
setattr(dict(), 'foo', {'bar': int})
raises an AttributeError (on Python 3.2). Could someone give me the
buzz word (or even an explanation) on why that is so?
Thomas Bach
More information about the Python-list
mailing list