Re: What do you call a class not intended to be instantiated

2008-09-28 Thread Ben Finney
Terry Reedy <[EMAIL PROTECTED]> writes: > Steven D'Aprano wrote: > > > And modules aren't callable. I've often thought they should be. > > Modules are not callable because their class, module, has no > __call__ instance method. But (in 3.0, which is all I will check) > you can subclass module an

Re: What do you call a class not intended to be instantiated

2008-09-28 Thread Terry Reedy
Steven D'Aprano wrote: And modules aren't callable. I've often thought they should be. Modules are not callable because their class, module, has no __call__ instance method. But (in 3.0, which is all I will check) you can subclass module and add one. >>> m = type(__builtins__) >>> m >>>

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Steven D'Aprano
On Sat, 27 Sep 2008 17:41:42 -0400, Terry Reedy wrote: > In 3.0, at least, one does not need a disk file to create a module. > > >>> import types > >>> me = types.ModuleType('me') # type(__builtins__) works, no import > >>> me > > >>> me.a = 1 > >>> me.a > 1 > >>> me.a + 1 > 2 Seems to wo

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aaron "Castironpi" Brady
On Sep 27, 6:16 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Aaron "Castironpi" Brady wrote: > class A(type): > > ...     def __call__( self, *ar ): > > ...             print 'call', self, ar > > ... > class B(object): > > ...     __metaclass__= A > > ... > B(3) > > call (3,) > > >

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Terry Reedy
Aaron "Castironpi" Brady wrote: class A(type): ... def __call__( self, *ar ): ... print 'call', self, ar ... class B(object): ... __metaclass__= A ... B(3) call (3,) Overriding the __call__ method of 'type' has the effect of giving you a static __call__ method on a cla

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Terry Reedy
Aahz wrote: In article <[EMAIL PROTECTED]>, Ben Finney <[EMAIL PROTECTED]> wrote: Steven D'Aprano <[EMAIL PROTECTED]> writes: I'd like to be able to call [a class] as if it were a function. Normally calling a class object returns an instance -- I wish to return something else. In that case,

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) wrote: > One cute reason to prefer class singletons to module singletons is that > subclassing works well for creating multiple singletons. But really, > the main reason I use class singletons is that they are the absolute > simplest way t

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aahz
In article <[EMAIL PROTECTED]>, Ben Finney <[EMAIL PROTECTED]> wrote: >Steven D'Aprano <[EMAIL PROTECTED]> writes: >> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote: >>> >>> An ordinary singleton is instantiating the class multiple times >>> yet returning the same instance object; a class singleto

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aaron "Castironpi" Brady
On Sep 27, 5:33 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote: > > Steven D'Aprano <[EMAIL PROTECTED]> writes: > > >> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote: > >> > An ordinary singleton is instantiating the class mu

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Steven D'Aprano
On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >> On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote: >> > An ordinary singleton is instantiating the class multiple times yet >> > returning the same instance object; a class singleton is simply us

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote: > > An ordinary singleton is instantiating the class multiple times > > yet returning the same instance object; a class singleton is > > simply using the class directly (like a module). Where is this "cl

Re: What do you call a class not intended to be instantiated

2008-09-26 Thread Steven D'Aprano
On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >>On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote: >>> >>> Seems to me that if all the module is used for is to store state, >>> you're wasting a file on disk. I personal

Re: What do you call a class not intended to be instantiated

2008-09-26 Thread Aahz
In article <[EMAIL PROTECTED]>, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote: >> >> Seems to me that if all the module is used for is to store state, you're >> wasting a file on disk. I personally prefer to use a class singleton. > >I don't recognise

Re: What do you call a class not intended to be instantiated

2008-09-26 Thread Steven D'Aprano
On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote: > Seems to me that if all the module is used for is to store state, you're > wasting a file on disk. I personally prefer to use a class singleton. I don't recognise the term "class singleton". Can you explain please? How is it different from an or

Re: What do you call a class not intended to be instantiated

2008-09-25 Thread Aahz
In article <[EMAIL PROTECTED]>, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >On 21 Sep 2008 22:39:47 GMT, Steven D'Aprano ><[EMAIL PROTECTED]> declaimed the following in >comp.lang.python: >> >> What do you call such a class? > > A wasted definition... The same functionality is achieved by

Re: What do you call a class not intended to be instantiated

2008-09-23 Thread Craig Allen
> > > Usegrammers? > usegrammers are just those that use grammars, but misspell it. -- http://mail.python.org/mailman/listinfo/python-list

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Craig Allen
> Snce when are "users" ever involved > in programming problems or programming > languages ? > since the begining, the first users are programmers, users of your libraries. -- http://mail.python.org/mailman/listinfo/python-list

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Aaron "Castironpi" Brady
On Sep 22, 6:55 pm, MRAB <[EMAIL PROTECTED]> wrote: > On Sep 22, 11:46 pm, "Aaron \"Castironpi\" Brady" > > > > <[EMAIL PROTECTED]> wrote: > > On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED] > > > cybersource.com.au> wrote: > > > On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote: > > > >

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread MRAB
On Sep 22, 11:46 pm, "Aaron \"Castironpi\" Brady" <[EMAIL PROTECTED]> wrote: > On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED] > > > > cybersource.com.au> wrote: > > On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote: > > > On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano > > >> But that's pr

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Aaron "Castironpi" Brady
On Sep 22, 5:32 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote: > > On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano > >> But that's precisely what I want to avoid: I don't want the objects to > >>  share *any* state, not even t

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Steven D'Aprano
On Mon, 22 Sep 2008 19:41:46 +1000, James Mills wrote: > On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano >> But that's precisely what I want to avoid: I don't want the objects to >> share *any* state, not even their class. I'm not trying for a Borg or >> Singleton: the user can call the factory as

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Aaron "Castironpi" Brady
On Sep 22, 3:28 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Aaron "Castironpi" Brady a écrit : > > > On Sep 22, 2:38 pm, Bruno Desthuilliers > > <[EMAIL PROTECTED]> wrote: > (snip) > >> Going back to robot-mode, Aaron ? > > > Not getting the same sense of "soul" as from my usual posts.  I

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Bruno Desthuilliers
Aaron "Castironpi" Brady a écrit : On Sep 22, 2:38 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: (snip) Going back to robot-mode, Aaron ? Not getting the same sense of "soul" as from my usual posts. I guess so. Might even drop the name change, too... Don't !-) while I'm at it. One

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Aaron "Castironpi" Brady
On Sep 22, 2:38 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Aaron "Castironpi" Brady a écrit : > > > > > On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote: > >> 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: > > Sounds to me like a functor, aka a function object: > http

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Bruno Desthuilliers
Aaron "Castironpi" Brady a écrit : On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote: 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: Sounds to me like a functor, aka a function object: http://en.wikipedia.org/wiki/Function_object Ok, then the simple solution is to implement a calla

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Terry Reedy
Steven D'Aprano wrote: Consider a factory function: def factory(x): # a toy example alist = [x] def foo(): return alist return foo Now suppose we "instantiate" the factory (for lack of a better term): f1 = factory(0) f2 = factory(0) Your factory is returning closures

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Matimus
On Sep 21, 3:39 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I have a class which is not intended to be instantiated. Instead of using > the class to creating an instance and then operate on it, I use the class > directly, with classmethods. Essentially, the class is used as

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Aaron "Castironpi" Brady
On Sep 22, 8:45 am, "Tim Rowe" <[EMAIL PROTECTED]> wrote: > 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: > > >> Sounds to me like a functor, aka a function object: > >>http://en.wikipedia.org/wiki/Function_object > > > Ok, then the simple solution is to implement a callable type (__call__ > >

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Tim Rowe
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: >> Sounds to me like a functor, aka a function object: >> http://en.wikipedia.org/wiki/Function_object >> > > Ok, then the simple solution is to implement a callable type (__call__ > method), possibly with appropriate support for the descriptor pr

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Arnaud Delobelle
On 22 Sep, 10:32, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > but it isn't good enough if the function needs to refer to it's own > state, because functions can only refer to themselves by name and the > factory can't know what name the function will be bound to. > > As far as I know, the only ob

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Bruno Desthuilliers
Tim Rowe a écrit : 2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: Steven D'Aprano a écrit : On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote: Steven D'Aprano a écrit : I have a class which is not intended to be instantiated. Instead of using the class to creating an instance

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Tim Rowe
2008/9/22 Bruno Desthuilliers <[EMAIL PROTECTED]>: > Steven D'Aprano a écrit : >> >> On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote: >> >>> Steven D'Aprano a écrit : I have a class which is not intended to be instantiated. Instead of using the class to creating an inst

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote: Steven D'Aprano a écrit : I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Es

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread James Mills
On 22 Sep 2008 09:07:43 GMT, Steven D'Aprano > But that's precisely what I want to avoid: I don't want the objects to > share *any* state, not even their class. I'm not trying for a Borg or > Singleton: the user can call the factory as many times as they want, but > the objects returned shouldn'

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Steven D'Aprano
On Mon, 22 Sep 2008 10:11:58 +0200, Bruno Desthuilliers wrote: > Steven D'Aprano a écrit : >> I have a class which is not intended to be instantiated. Instead of >> using the class to creating an instance and then operate on it, I use >> the class directly, with classmethods. Essentially, the clas

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I don't want the objects to share state. I'm not exactly sure what I > said that has given so many people the impression that I do. This: Steven D'Aprano <[EMAIL PROTECTED]> writes: > Essentially, the class is used as a function that keeps state fr

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Steven D'Aprano
On Mon, 22 Sep 2008 10:12:38 +1000, James Mills wrote: > On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <[EMAIL PROTECTED]> > wrote: >> I call it an obvious misuse and misunderstanding of why you'd use a >> class in the first place. Either create an instance and not make these >> things classmet

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the class is used as a function that keeps state from one call to the next. T

Re: What do you call a class not intended to be instantiated

2008-09-22 Thread Rhamphoryncus
On Sep 21, 4:39 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I have a class which is not intended to be instantiated. Instead of using > the class to creating an instance and then operate on it, I use the class > directly, with classmethods. Essentially, the class is used as

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Ben Finney
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I have a class which is not intended to be instantiated. Instead of > using the class to creating an instance and then operate on it, I > use the class directly, with classmethods. Essentially, the class is > used as a function that keeps state from on

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Aaron "Castironpi" Brady
On Sep 21, 6:05 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > Fixing top-posting. > > On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote: > > On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano > > <[EMAIL PROTECTED]> wrote: > >> I have a class which is not intended to be inst

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <[EMAIL PROTECTED]> wrote: > I call it an obvious misuse and misunderstanding of why you'd use a class in > the first place. Either create an instance and not make these things > classmethods or just share the stuff in a module-level set of variables

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread bearophileHUGS
Steven D'Aprano: > I have a class which is not intended to be instantiated. Instead of using > the class to creating an instance and then operate on it, I use the class > directly, with classmethods. Essentially, the class is used as a function > that keeps state from one call to the next. You may

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Calvin Spealman
I call it an obvious misuse and misunderstanding of why you'd use a class in the first place. Either create an instance and not make these things classmethods or just share the stuff in a module-level set of variables. But the instantiating is the best options. Your class attributes might not be gl

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
On Mon, Sep 22, 2008 at 9:05 AM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > I'm not wedded to the idea, there are alternatives (perhaps the factory > should instantiate the class and return that?) but I assume others have > used this design and have a name for it. The problem is, I don't see why

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread Steven D'Aprano
Fixing top-posting. On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote: > On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: >> I have a class which is not intended to be instantiated. Instead of >> using the class to creating an instance and then operate on it, I us

Re: What do you call a class not intended to be instantiated

2008-09-21 Thread James Mills
Hi, Wouldn't a normal class called State suffice for storing state between calls ? And ... Creating a state instance ? For example: class State(object): """State() -> new state object Creates a new state object that is suitable for holding different states of an application. Usefull

What do you call a class not intended to be instantiated

2008-09-21 Thread Steven D'Aprano
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the class is used as a function that keeps state from one call to the next. The problem is that I don't k