Re: design question: no new attributes

2007-03-14 Thread Harold Fellermann
Hi Alan, > One last point. While I remain interested in examples of how > "late" addition ofattributesto class instances is useful, > I must note that everyone who responded agreed that it > has been a source of bugs. This seems to argue against a > general ban on "locking" objects in some way, i

Re: design question: no new attributes

2007-03-04 Thread Arnaud Delobelle
On Feb 26, 9:48 pm, "Alan Isaac" <[EMAIL PROTECTED]> wrote: > I have a class whose instances should only receive attribute > assignments for attributes that were created at inititialization. > If slots are not appropriate, what is the Pythonic design for this? Hi ! Even though a lot of people hav

Re: design question: no new attributes

2007-03-01 Thread Diez B. Roggisch
> > One last point. While I remain interested in examples of how > "late" addition of attributes to class instances is useful, > I must note that everyone who responded agreed that it > has been a source of bugs. This seems to argue against a > general ban on "locking" objects in some way, in som

Re: design question: no new attributes

2007-03-01 Thread Bruno Desthuilliers
Alan Isaac a écrit : > The security application seems to call for roles. Considering that a role is a set of permissions in a context. The application doesn't want to say "you need this role", but "you need to have a role that has this permission" (nb : this is based on Zope's security model).

Re: design question: no new attributes

2007-03-01 Thread Alan Isaac
The security application seems to call for roles. I'll have to think about the schema example. But in any case, my question was poorly stated. I started out wanting to trap was the dynamic addition of attributes to class instances after initialization. While you responded to my later question as as

Re: design question: no new attributes

2007-03-01 Thread Bruno Desthuilliers
Alan Isaac a écrit : > "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in > message news:[EMAIL PROTECTED] > >>I don't share your definition of "reasonable". But you should have >>guessed by now > > > My view may be shaped by a different experience. > I have found dynamic attribute creation conv

Re: design question: no new attributes

2007-03-01 Thread Paul Boddie
On 28 Feb, 15:39, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > However I will observe that > > - entire languages are structured on the premise that dynamic > > attribute creation can be hazardous > > Yup, and you are free to use one of them. And as an additional benefit, they > will be more p

Re: design question: no new attributes

2007-03-01 Thread Alan Isaac
"greg" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > There's a problem with that when you want to subclass: Agreed. The following addresses that and, I think, some of the other objections that have been raised. Alan class Lockable: a = 0 def __init__(self, lock=False):

Re: design question: no new attributes

2007-03-01 Thread Alan Isaac
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I don't share your definition of "reasonable". But you should have > guessed by now My view may be shaped by a different experience. I have found dynamic attribute creation convenient when doing something "quick a

Re: design question: no new attributes

2007-03-01 Thread Michele Simionato
On Feb 26, 10:48 pm, "Alan Isaac" <[EMAIL PROTECTED]> wrote: > I have a class whose instances should only receive attribute > assignments for attributes that were created at inititialization. > If slots are not appropriate, what is the Pythonic design for this? > > Thanks, > Alan Isaac There is a

Re: design question: no new attributes

2007-03-01 Thread greg
Alan Isaac wrote: > class NothingNew: > a = 0 > def __init__(self): > self.b = 1 > self.initialized = True There's a problem with that when you want to subclass: class NothingElseNew(NothingNew): def __init__(self): NothingNew.__init__(self) self.c

Re: design question: no new attributes

2007-02-28 Thread Gabriel Genellina
En Wed, 28 Feb 2007 09:41:47 -0300, Alan Isaac <[EMAIL PROTECTED]> escribió: > However I will observe that > - entire languages are structured on the premise that dynamic > attribute creation can be hazardous That's why we have so many languages to choose from. What is highly important for so

Re: design question: no new attributes

2007-02-28 Thread Bruno Desthuilliers
Alan Isaac a écrit : > Ben Finney writes: > >>Really, though, adding attributes to an instance is a normal thing to >>do in Python, and you've not yet shown why you want that normal >>functionality to be special-cased here. > > > > I accept your earlier point that if an interface changes > one

Re: design question: no new attributes

2007-02-28 Thread Diez B. Roggisch
> However I will observe that > - entire languages are structured on the premise that dynamic > attribute creation can be hazardous Yup, and you are free to use one of them. And as an additional benefit, they will be more performant because you then can optimize the code further. But they certain

Re: design question: no new attributes

2007-02-28 Thread Alan Isaac
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The easy, but inelegant, way is to set a flag. That is the approach I explored here: http://mail.python.org/pipermail/python-list/2007-February/428562.html Btw, I add some background comments about "why" here: http://

Re: design question: no new attributes

2007-02-28 Thread Alan Isaac
Ben Finney writes: > Really, though, adding attributes to an instance is a normal thing to > do in Python, and you've not yet shown why you want that normal > functionality to be special-cased here. I accept your earlier point that if an interface changes one can just trap use of the old interfac

Re: design question: no new attributes

2007-02-27 Thread Steven D'Aprano
On Tue, 27 Feb 2007 20:59:03 +, Alan Isaac wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > class Difficult(object): > def __setattr__(self, name, value): > if self.__dict__.has_key(name): > print "'%s' exists as an instance att

Re: design question: no new attributes

2007-02-27 Thread Ben Finney
"Alan Isaac" <[EMAIL PROTECTED]> writes: > OK, let me approach this from a new direction. Suppose I define a > class that behaves I think as I stipulated:: > > class NothingNew: > a = 0 > def __init__(self): > self.b = 1 > self.initialized = True > def __setattr__(self

Re: design question: no new attributes

2007-02-27 Thread Alan Isaac
OK, let me approach this from a new direction. Suppose I define a class that behaves I think as I stipulated:: class NothingNew: a = 0 def __init__(self): self.b = 1 self.initialized = True def __setattr__(self, attr, val): if not hasattr(self,'initialized') or

Re: design question: no new attributes

2007-02-27 Thread Chris Mellon
On 2/27/07, Alan Isaac <[EMAIL PROTECTED]> wrote: > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > def __setattr__(self, attr, val): > > if hasattr(self, attr): > > self.__dict__[attr] = val > > else: > > # Tell the user off > > But then

Re: design question: no new attributes

2007-02-27 Thread Alan Isaac
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > def __setattr__(self, attr, val): > if hasattr(self, attr): > self.__dict__[attr] = val > else: > # Tell the user off But then you cannot even set attributes during initialization, right? I wan

Re: design question: no new attributes

2007-02-27 Thread Alan Isaac
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] class Difficult(object): def __setattr__(self, name, value): if self.__dict__.has_key(name): print "'%s' exists as an instance attribute" % name self.__dict__[name] = value elif

Re: design question: no new attributes

2007-02-26 Thread Ben Finney
"Alan Isaac" <[EMAIL PROTECTED]> writes: > "Ben Finney" <[EMAIL PROTECTED]> wrote: > > The Pythonic design is: don't expect to have such control over > > users of your code. > > I know this is a popular response, but the fact of the matter > remains that it can be helpful to know when someone trie

Re: design question: no new attributes

2007-02-26 Thread Arnaud Delobelle
On 27 Feb, 06:40, "Alan Isaac" <[EMAIL PROTECTED]> wrote: > So my question remains: > how best to trap any such attempt > subsequent to object initialization? > (I am willing to have properties for > all data attributes, if that helps.) > You can define the __setattr__ method in your class as def

Re: design question: no new attributes

2007-02-26 Thread Steven D'Aprano
On Tue, 27 Feb 2007 06:40:29 +, Alan Isaac wrote: > "Ben Finney" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> The Pythonic design is: don't expect to have such control over users >> of your code. > > I know this is a popular response, It's popular for good reason. > but

Re: design question: no new attributes

2007-02-26 Thread Alan Isaac
"Ben Finney" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The Pythonic design is: don't expect to have such control over users > of your code. I know this is a popular response, but the fact of the matter remains that it can be helpful to know when someone tries to set a value for

Re: design question: no new attributes

2007-02-26 Thread Ben Finney
"Alan Isaac" <[EMAIL PROTECTED]> writes: > I have a class whose instances should only receive attribute > assignments for attributes that were created at inititialization. > If slots are not appropriate, what is the Pythonic design for this? The Pythonic design is: don't expect to have such contr

Re: design question: no new attributes

2007-02-26 Thread Larry Bates
Alan Isaac wrote: > I have a class whose instances should only receive attribute > assignments for attributes that were created at inititialization. > If slots are not appropriate, what is the Pythonic design for this? > > Thanks, > Alan Isaac > > My understanding of "Pythonic design" is not to

design question: no new attributes

2007-02-26 Thread Alan Isaac
I have a class whose instances should only receive attribute assignments for attributes that were created at inititialization. If slots are not appropriate, what is the Pythonic design for this? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list