Re: DRY and static attribute for multiple classes.

2011-02-03 Thread Marc Aymerich
On Feb 3, 10:24 am, Peter Otten <__pete...@web.de> wrote: > Marc Aymerich wrote: > > On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: > >> Marc Aymerich wrote: > > Hi!, > > Unfortunately per_class attribute losses the "independence" when I try > > to mix it with django models.Model . > > >

Re: DRY and static attribute for multiple classes.

2011-02-03 Thread Peter Otten
Marc Aymerich wrote: > On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: >> Marc Aymerich wrote: > Hi!, > Unfortunately per_class attribute losses the "independence" when I try > to mix it with django models.Model . > > from django.db import models > class Plugin(models.base.ModelBase):

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Marc Aymerich
On Feb 2, 5:58 pm, Michele Simionato wrote: > Notice that Peter's approach also works without inheritance: > > registries = {} > > @property > def per_class(self): >    cls = type(self) >    try: >       return registries[cls] >    except KeyError: >       result = registries[cls] = [] >       ret

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Michele Simionato
Notice that Peter's approach also works without inheritance: registries = {} @property def per_class(self): cls = type(self) try: return registries[cls] except KeyError: result = registries[cls] = [] return result class A(object): per_class=per_class class B(object): p

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Marc Aymerich
On Feb 2, 12:18 pm, Peter Otten <__pete...@web.de> wrote: > Marc Aymerich wrote: > > On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: > >> Marc Aymerich wrote: > >> > Hi all, > >> > I want to provide an encapsulated static attribute called _registry > >> > for several classes. > > >> > I t

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Marc Aymerich
On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: > Marc Aymerich wrote: > > Hi all, > > I want to provide an encapsulated static attribute called _registry > > for several classes. > > > I try to use inheritance in order to make it DRY: all classes inherit > > from a BaseClass that impleme

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Peter Otten
Marc Aymerich wrote: > On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: >> Marc Aymerich wrote: >> > Hi all, >> > I want to provide an encapsulated static attribute called _registry >> > for several classes. >> >> > I try to use inheritance in order to make it DRY: all classes inherit >>

Re: DRY and static attribute for multiple classes.

2011-02-02 Thread Marc Aymerich
On Feb 2, 12:11 am, Peter Otten <__pete...@web.de> wrote: > Marc Aymerich wrote: > > Hi all, > > I want to provide an encapsulated static attribute called _registry > > for several classes. > > > I try to use inheritance in order to make it DRY: all classes inherit > > from a BaseClass that impleme

Re: DRY and static attribute for multiple classes.

2011-02-01 Thread Peter Otten
Marc Aymerich wrote: > Hi all, > I want to provide an encapsulated static attribute called _registry > for several classes. > > I try to use inheritance in order to make it DRY: all classes inherit > from a BaseClass that implements the _registry encapsulation. But with > inheritance it doesn't w

DRY and static attribute for multiple classes.

2011-02-01 Thread Marc Aymerich
Hi all, I want to provide an encapsulated static attribute called _registry for several classes. I try to use inheritance in order to make it DRY: all classes inherit from a BaseClass that implements the _registry encapsulation. But with inheritance it doesn't work how I want, because a single ins