Re: Preventing class methods from being defined

2006-01-17 Thread David Hirschfield
I realize now that it would probably be best to define the problem I'm having according to the constraints imposed by other requirements, and not by describing the basic functionality. That way, since there are so many possible ways to get something like what I want, there will probably be only

Re: Preventing class methods from being defined

2006-01-17 Thread David Hirschfield
>>bit more insight into the arrangement I'm trying to get: >> >>restrict = True >> >> >Why a global value? If it is to affect class instantiation, why not pass it >or a value to the constructor, e.g., C(True) or C(some_bool)? > > > For reasons unrelated to this problem, the class that does t

Re: Preventing class methods from being defined

2006-01-17 Thread Bengt Richter
On Mon, 16 Jan 2006 18:55:43 -0800, David Hirschfield <[EMAIL PROTECTED]> wrote: >Thanks for this, it's a great list of the ways it can be done. Here's a Actually, your way is yet another ;-) >bit more insight into the arrangement I'm trying to get: > >restrict = True Why a global value? If it i

Re: Preventing class methods from being defined

2006-01-16 Thread David Hirschfield
Thanks for this, it's a great list of the ways it can be done. Here's a bit more insight into the arrangement I'm trying to get: restrict = True class A(object): _restrict = ["test"] def _null(self, *args, **kws): raise Exception,"not allowed to access" def test(s

Re: Preventing class methods from being defined

2006-01-16 Thread Bengt Richter
On Sun, 15 Jan 2006 19:23:30 -0800, David Hirschfield <[EMAIL PROTECTED]> wrote: >I should have explicitly mentioned that I didn't want this particular >solution, for a number of silly reasons. >Is there another way to make this work, without needing to place an >explicit "if allowed" around eac

Re: Preventing class methods from being defined

2006-01-16 Thread Steven D'Aprano
On Mon, 16 Jan 2006 06:39:48 -0500, Dan Sommers wrote: > By the principle of least surprise, if dir(some_sobject) contains foo, > then some_object.foo should *not* raise a NameError. Good thinking. Yes, it should raise a different exception. -- Steven. -- http://mail.python.org/mailman/listin

Re: Preventing class methods from being defined

2006-01-16 Thread Dan Sommers
On Mon, 16 Jan 2006 21:25:50 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 15 Jan 2006 18:41:02 -0800, David Hirschfield wrote: >> Here's a strange concept that I don't really know how to implement, but >> I suspect can be implemented via descriptors or metaclasses somehow: >> >> I

Re: Preventing class methods from being defined

2006-01-16 Thread Steven D'Aprano
On Sun, 15 Jan 2006 18:41:02 -0800, David Hirschfield wrote: > Here's a strange concept that I don't really know how to implement, but > I suspect can be implemented via descriptors or metaclasses somehow: > > I want a class that, when instantiated, only defines certain methods if > a global in

Re: Preventing class methods from being defined

2006-01-15 Thread Alex Martelli
David Hirschfield <[EMAIL PROTECTED]> wrote: > Here's a strange concept that I don't really know how to implement, but > I suspect can be implemented via descriptors or metaclasses somehow: Yeah, a custom metaclass will do it, easily. > I want a class that, when instantiated, only defines certai

Re: Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
I should have explicitly mentioned that I didn't want this particular solution, for a number of silly reasons. Is there another way to make this work, without needing to place an explicit "if allowed" around each method definition? Thanks again, -David Dan Sommers wrote: >On Sun, 15 Jan 2006 1

Re: Preventing class methods from being defined

2006-01-15 Thread Dan Sommers
On Sun, 15 Jan 2006 18:41:02 -0800, David Hirschfield <[EMAIL PROTECTED]> wrote: > I want a class that, when instantiated, only defines certain methods > if a global indicates it is okay to have those methods. So I want > something like: > global allow > allow = ["foo","bar"] > class A: > de

Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
Here's a strange concept that I don't really know how to implement, but I suspect can be implemented via descriptors or metaclasses somehow: I want a class that, when instantiated, only defines certain methods if a global indicates it is okay to have those methods. So I want something like: gl