James Stroud wrote:
> However, I think that what you are saying about metaclasses being
> brittle relates more to implementation than language. In theory, these
> should be equivalent:
>
> (1) class Bob(object): pass
> (2) Bob = type('Bob', (), {})
>
> And indeed a cursory inspection of the
Carl Banks wrote:
> You sound as if you're avoiding metaclasses just for the sake of
> avoiding them, which is just as bad as using them for the sake of using
> them.
Do you realize that you are effectively saying "avoiding a complex
tool in favor of a simpler one is just as bad as avoing the simp
Michele Simionato wrote:
> George Sakkis wrote:
>
>>Why is this less hidden or magical than a metaclass ?
>
>
> Because it does not use inheritance. It is not going to create
> properties on subclasses without
> you noticing it. Also, metaclasses are brittle: try to use them with
> __slots__, or
Michele Simionato wrote:
> Carl Banks wrote:
> > Come on, I don't think anyone's under the impression we're being
> > indiscriminate here.
>
> Ok, but I don't think that in the case at hand we should recommend a
> metaclass
> solution.
You sound as if you're avoiding metaclasses just for the sake
Carl Banks wrote:
> Come on, I don't think anyone's under the impression we're being
> indiscriminate here.
Ok, but I don't think that in the case at hand we should recommend a
metaclass
solution.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Michele Simionato wrote:
> Carl Banks wrote:
> > Devil's Advocate: he did say "hidden magic TO YOUR CLASS".
> >
> > If you use a (real) metaclass, then you have the icky feeling of a
> > class permanently tainted by the unclean metaclass (even though the
> > metaclass does nothing other than touch
George Sakkis wrote:
> There's a subtle common bug here: all _get and _set closures will refer
> to the last property only. You have to remember to write "def
> _set(self,v,prop=prop)" and similarly for _get to do the right thing.
Sorry. My mistake.
> By the way, I can't think of a case where t
Carl Banks wrote:
> Devil's Advocate: he did say "hidden magic TO YOUR CLASS".
>
> If you use a (real) metaclass, then you have the icky feeling of a
> class permanently tainted by the unclean metaclass (even though the
> metaclass does nothing other than touch the class dict upon creation);
> wher
George Sakkis wrote:
> Michele Simionato wrote:
> > import sys
> >
> > def defprop(name, default=127):
> > loc = sys._getframe(1).f_locals
> > prop = '_%s' % name
> > def _set(self, v):
> > v_new = v % 256
> > setattr(self, prop, v_new)
> > def _get(self):
> >
George Sakkis wrote:
>
> from itertools import chain, izip, repeat
>
> def ByteProperties(*names, **defaulted_names):
> def byte_property(name, default):
> return property(lambda self: getattr(self, name, default),
> lambda self,v: setattr(self, name, v%256))
>
George Sakkis wrote:
>
> Why is this less hidden or magical than a metaclass ?
Because it does not use inheritance. It is not going to create
properties on subclasses without
you noticing it. Also, metaclasses are brittle: try to use them with
__slots__, or with non-standard
classes (i.e. extensio
Carl Banks wrote:
> Lee Harr wrote:
> > I understand how to create a property like this:
> >
> > class RC(object):
> > def _set_pwm(self, v):
> > self._pwm01 = v % 256
> > def _get_pwm(self):
> > return self._pwm01
> > pwm01 = property(_get_pwm, _set_pwm)
> >
> >
> > But
Michele Simionato wrote:
> Lee Harr wrote:
> > I understand how to create a property like this:
> >
> > class RC(object):
> > def _set_pwm(self, v):
> > self._pwm01 = v % 256
> > def _get_pwm(self):
> > return self._pwm01
> > pwm01 = property(_get_pwm, _set_pwm)
> >
> >
Lee Harr wrote:
> I understand how to create a property like this:
>
> class RC(object):
> def _set_pwm(self, v):
> self._pwm01 = v % 256
> def _get_pwm(self):
> return self._pwm01
> pwm01 = property(_get_pwm, _set_pwm)
>
>
> But what if I have a whole bunch of these pw
Lee Harr wrote:
> I understand how to create a property like this:
>
> class RC(object):
> def _set_pwm(self, v):
> self._pwm01 = v % 256
> def _get_pwm(self):
> return self._pwm01
> pwm01 = property(_get_pwm, _set_pwm)
>
>
> But what if I have a whole bunch of these pwm
In <[EMAIL PROTECTED]>, Lee Harr wrote:
> But what if I have a whole bunch of these pwm properties?
>
> I made this:
>
> class RC(object):
> def _makeprop(name):
> prop = '_%s' % name
> def _set(self, v):
> v_new = v % 256
> setattr(self, prop, v_new)
Lee Harr wrote:
> I understand how to create a property like this:
>
> class RC(object):
> def _set_pwm(self, v):
> self._pwm01 = v % 256
> def _get_pwm(self):
> return self._pwm01
> pwm01 = property(_get_pwm, _set_pwm)
>
>
> But what if I have a whole bunch of these
I understand how to create a property like this:
class RC(object):
def _set_pwm(self, v):
self._pwm01 = v % 256
def _get_pwm(self):
return self._pwm01
pwm01 = property(_get_pwm, _set_pwm)
But what if I have a whole bunch of these pwm properties?
I made this:
class
18 matches
Mail list logo