Re: Potential pitfalls when going from old-style to new-style classes

2014-11-19 Thread Chris Kaynor
run pylint over a bit of > code and it complains that Foo is old-school, I make the obvious > change to inherit from object. While I do this mostly to shut up > pylint so I can focus on more serious messages, I must admit I have > never experienced any problem changing from old-styl

Re: Potential pitfalls when going from old-style to new-style classes

2014-11-19 Thread Ethan Furman
over a bit of > code and it complains that Foo is old-school, I make the obvious > change to inherit from object. While I do this mostly to shut up > pylint so I can focus on more serious messages, I must admit I have > never experienced any problem changing from old-style to new-style

Potential pitfalls when going from old-style to new-style classes

2014-11-19 Thread Skip Montanaro
to inherit from object. While I do this mostly to shut up pylint so I can focus on more serious messages, I must admit I have never experienced any problem changing from old-style to new-style classes. Under what circumstances might this be problematic? Thx, Skip -- https://mail.python.org/mailman

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-21 Thread Terry Reedy
On 6/20/2011 9:26 PM, John Salerno wrote: I can't quite seem to find the answer to this anywhere. The book I'm reading right now was written for Python 3.1 and doesn't use (object), so I'm thinking that was just a way to force new-style classes in 2.x and is no longer neces

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread Ben Finney
John Salerno writes: > I can't quite seem to find the answer to this anywhere. The book I'm > reading right now was written for Python 3.1 and doesn't use (object), > so I'm thinking that was just a way to force new-style classes in 2.x > and is no longer necessar

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread John Salerno
7;m thinking that was just a way to force new-style classes in 2.x > > and is no longer necessary in 3.x. Is that right? > > > (The documentation doesn't mention object anymore, but elsewhere on > > the Python website it says the documentation hasn't been updated for &

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread Benjamin Kaplan
On Mon, Jun 20, 2011 at 6:26 PM, John Salerno wrote: > I can't quite seem to find the answer to this anywhere. The book I'm > reading right now was written for Python 3.1 and doesn't use (object), > so I'm thinking that was just a way to force new-style classes in 2.x

Do we still need to inherit from "object" to create new-style classes?

2011-06-20 Thread John Salerno
I can't quite seem to find the answer to this anywhere. The book I'm reading right now was written for Python 3.1 and doesn't use (object), so I'm thinking that was just a way to force new-style classes in 2.x and is no longer necessary in 3.x. Is that right? (The documenta

Re: mixins and new style classes

2010-02-17 Thread Bruno Desthuilliers
mk a écrit : class Person(object): > ... pass > ... class Friendly(object): > ... def hello(self): > ... print 'hello' > ... Person.__bases__ += (Friendly,) > Traceback (most recent call last): > File "", line 1, in > TypeError: Cannot create a consistent

mixins and new style classes

2010-02-17 Thread mk
>>> class Person(object): ... pass ... >>> class Friendly(object): ... def hello(self): ... print 'hello' ... >>> >>> Person.__bases__ += (Friendly,) Traceback (most recent call last): File "", line 1, in TypeError: Cannot create a consistent method resolution order (MRO) fo

Re: new style classes, __new__, __init__

2008-09-16 Thread Christian Heimes
Torsten Mohr wrote: I just found an article that describes it better, this example works: class C2(object): def __new__(cls, a): obj = object.__new__(cls) print "new called" obj.a = 8 return obj __new__ = staticmethod(__new__) Staticmethod isnt' requir

Re: new style classes, __new__, __init__

2008-09-16 Thread Torsten Mohr
Hello, > This way __new__ is not called, if i remove __init__ then > there are too many parameters to __new__, if i add a parameter > to __new__ then it says that __new__ does not take arguments. I just found an article that describes it better, this example works: class C2(object): def __ne

Re: new style classes, __new__, __init__

2008-09-16 Thread Larry Bates
Torsten Mohr wrote: Hi, i have some questions related to new style classes, they look quite useful but i wonder if somebody can give me an example on constructors using __new__ and on using __init__ ? I just see that when using it i can't give parameters to __new__ and when i additio

new style classes, __new__, __init__

2008-09-16 Thread Torsten Mohr
Hi, i have some questions related to new style classes, they look quite useful but i wonder if somebody can give me an example on constructors using __new__ and on using __init__ ? I just see that when using it i can't give parameters to __new__ and when i additionally define __init__

Re: Impossible to change methods with special names of instances of new-style classes?

2008-07-10 Thread Bruno Desthuilliers
samwyse a écrit : On Jul 8, 4:56 pm, Joseph Barillari <[EMAIL PROTECTED]> wrote: My question is: did something about the way the special method names are implemented change for new-style classes? Just off the top of my head, I'd guess that it's due to classes already

Re: Impossible to change methods with special names of instances of new-style classes?

2008-07-10 Thread Steven D'Aprano
On Tue, 08 Jul 2008 17:56:45 -0400, Joseph Barillari wrote: > Hi python-list, > > I've just started using new-style classes and am a bit confused as to > why I can't seem to alter methods with special names (__call__, etc.) of > new-style class instances. [deploy weapo

Re: Impossible to change methods with special names of instances of new-style classes?

2008-07-09 Thread Terry Reedy
samwyse wrote: On Jul 8, 4:56 pm, Joseph Barillari <[EMAIL PROTECTED]> wrote: My question is: did something about the way the special method names are implemented change for new-style classes? I believe the difference is that for new-style classes, when special methods are called &

Re: Impossible to change methods with special names of instances of new-style classes?

2008-07-09 Thread samwyse
On Jul 8, 4:56 pm, Joseph Barillari <[EMAIL PROTECTED]> wrote: > My question is: did something about the way the special method names are > implemented change for new-style classes? Just off the top of my head, I'd guess that it's due to classes already having a default

Re: Impossible to change methods with special names of instances of new-style classes?

2008-07-09 Thread cokofreedom
> > My question is: did something about the way the special method names are > implemented change for new-style classes? > >>> class old: pass >>> class new(object): pass >>> testone = old() >>> testone.__call__ = lambda : 33

Impossible to change methods with special names of instances of new-style classes?

2008-07-08 Thread Joseph Barillari
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other words, I can do this: >>> class Z: ... pass ... >>> z = Z() >&g

Re: Times where one would use new style classes vs classic classes

2008-07-03 Thread Quek
On Jul 3, 3:11 pm, Bruno Desthuilliers wrote: > Quek a écrit : > > > Hi all, > > > I'm reallynewto Python and I've been reading up some texts on older > > versions of Python (2.2 to be specific). > > > The text briefly mentionednewstyleand classic classes. > > > I'd really like to know in the curr

Re: Times where one would use new style classes vs classic classes

2008-07-03 Thread Bruno Desthuilliers
cases of multi-inheritance, where would I use new style classes? Everywhere you don't have to support compat with ages-old versions of Python. MI is not the main point of newstyle classes (FWIW, you can do MI with old-style classes too), they have quite a lot more to offer. Consider "cla

Re: Times where one would use new style classes vs classic classes

2008-07-02 Thread Ben Finney
Quek <[EMAIL PROTECTED]> writes: > I'd really like to know in the current context of Python 2.5, > besides in the cases of multi-inheritance, where would I use new > style classes? Is it a norm to use more new style classes even if I > don't have multi-inheritance

Re: Times where one would use new style classes vs classic classes

2008-07-02 Thread Daniel Fetchinson
he cases of multi-inheritance, where would I use new style > classes? Is it a norm to use more new style classes even if I don't > have multi-inheritance in the industry, open source projects, etc > today? > > If this isn't the right place to ask these questions, could some one

Times where one would use new style classes vs classic classes

2008-07-02 Thread Quek
, where would I use new style classes? Is it a norm to use more new style classes even if I don't have multi-inheritance in the industry, open source projects, etc today? If this isn't the right place to ask these questions, could some one point me somewhere more appropriat

Re: should I put old or new style classes in my book?

2008-05-30 Thread Alan G Isaac
Alan Isaac <[EMAIL PROTECTED]> writes: I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Arnaud Delobelle wrote: I don't know where it is stated, but how could they *not* be equivalent? The most obvious wa

Re: should I put old or new style classes in my book?

2008-05-30 Thread Aahz
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > >Anyway, I am posting to ask about the current status of new style >classes. I am planning to present only one style in the book, because >the differences between them don't matter for anything I am doin

Re: should I put old or new style classes in my book?

2008-05-30 Thread Arnaud Delobelle
"Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > On Thu, May 29, 2008 at 3:06 PM, Jason <[EMAIL PROTECTED]> wrote: >> I've got Python 3.0 alpha 2. In this version, it looks like you can >> define classes in either the old style or new style. (I snipped the >> top line a bit in the following exa

Re: should I put old or new style classes in my book?

2008-05-30 Thread Eduardo O. Padoan
On Thu, May 29, 2008 at 3:06 PM, Jason <[EMAIL PROTECTED]> wrote: > I've got Python 3.0 alpha 2. In this version, it looks like you can > define classes in either the old style or new style. (I snipped the > top line a bit in the following example): Wrong. Py3k Classes are always new-style. They

Re: should I put old or new style classes in my book?

2008-05-30 Thread Bruno Desthuilliers
version at thinkpython.com; I am revising now, so I welcome all comments, suggestions, corrections, etc. Anyway, I am posting to ask about the current status of new style classes. I am planning to present only one style in the book, because the differences between them don't matter for anything

Re: should I put old or new style classes in my book?

2008-05-30 Thread sturlamolden
On May 29, 6:07 pm, [EMAIL PROTECTED] wrote: > The current edition of the book presents old style classes. I am > considering > switching to new style classes on the assumption that this should be > the default > choice for new programs. The drawback is that a lot of the online

Re: should I put old or new style classes in my book?

2008-05-30 Thread Carl Banks
On May 29, 12:07 pm, [EMAIL PROTECTED] wrote: > The current edition of the book presents old style classes. I am > considering > switching to new style classes on the assumption that this should be > the default > choice for new programs. The drawback is that a lot of the online

Re: should I put old or new style classes in my book?

2008-05-30 Thread Matthieu Brucher
ass > > > > Is that correct, and if so, where is it stated explicitly? > > (I know about the "all classes are new style classes" statement.) > All classes are new style classes, and the usual class MyClass(object) pass should be replaced by the first class MyClass: pass

Re: should I put old or new style classes in my book?

2008-05-30 Thread Arnaud Delobelle
where is it stated explicitly? > (I know about the "all classes are new style classes" statement.) I don't know where it is stated, but how could they *not* be equivalent? > 2. I take it from this thread that in Python 2.2+ if I put the > following at the top of a module

Re: should I put old or new style classes in my book?

2008-05-29 Thread Alan Isaac
This thread raises two questions for me. 1. I take it from this thread that in Python 3 the following are equivalent: class Test: pass class Test(object): pass Is that correct, and if so, where is it stated explicitly? (I know about the "all classes are new

Re: should I put old or new style classes in my book?

2008-05-29 Thread Arnaud Delobelle
Cambridge >> University Press, but there will still be a free version under the GNU >> FDL. >> >> You can see the latest version at thinkpython.com; I am revising now, >> so >> I welcome all comments, suggestions, corrections, etc. >> >> Anyway, I am

Re: should I put old or new style classes in my book?

2008-05-29 Thread Jason
n under the GNU > FDL. > > You can see the latest version at thinkpython.com; I am revising now, > so > I welcome all comments, suggestions, corrections, etc. > > Anyway, I am posting to ask about the current status of new style > classes. > I am planning to present only

Re: should I put old or new style classes in my book?

2008-05-29 Thread Benjamin Kaplan
ill still be a free version under the GNU > FDL. > > You can see the latest version at thinkpython.com; I am revising now, > so > I welcome all comments, suggestions, corrections, etc. > > Anyway, I am posting to ask about the current status of new style > classes. > I am p

Re: should I put old or new style classes in my book?

2008-05-29 Thread Matthieu Brucher
Hi, New style classes should be put as the default. This is what I did, based on the principle that new classes were introduces in Python 2.2 and that we are now at 2.5 and soon 2.6. Tutorials that use old style classes may be old and perhaps won't be updated ever. That's not a problem.

should I put old or new style classes in my book?

2008-05-29 Thread allendowney
revising now, so I welcome all comments, suggestions, corrections, etc. Anyway, I am posting to ask about the current status of new style classes. I am planning to present only one style in the book, because the differences between them don't matter for anything I am doing in the book. The cu

Re: Monkey patching new style classes

2007-11-29 Thread Terry Reedy
"David Coffin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Is it possible to add an attribute to a new style class where the name of | that attribute is determined at runtime? >>> class C(object): pass >>> setattr(C,'a',1) >>> C.a 1 And hasattr, getattr work also. -- htt

Monkey patching new style classes

2007-11-29 Thread David Coffin
Is it possible to add an attribute to a new style class where the name of that attribute is determined at runtime? In other words, is there an new style class alternative to adding items to a classes __dict__ ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically removing methods in new-style classes

2007-09-12 Thread Steven D'Aprano
On Wed, 12 Sep 2007 14:28:15 +, agupta0318 wrote: > I am trying unsuccessfully to remove some methods from an instance, > based on values passed in to the constructor as in the following > example: [snip] >>> class C(object): ... def method(self): ... return "method exists"

Re: Dynamically removing methods in new-style classes

2007-09-12 Thread Michele Simionato
On Sep 12, 4:28 pm, [EMAIL PROTECTED] wrote: > I am trying unsuccessfully to remove some methods from an instance, Usuall one does not remove methods, but wraps the object and delegates only to a restricted number of methods. Is this solution viable? If not, you may be forced to change the class o

Re: Dynamically removing methods in new-style classes

2007-09-12 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes: > I am trying unsuccessfully to remove some methods from an instance, You can't remove the method from an instance because the method is stored in its class. > With the older python classes I could have done: > self.__class__.__dict__[''test1"] to achieve the desire

Dynamically removing methods in new-style classes

2007-09-12 Thread agupta0318
I am trying unsuccessfully to remove some methods from an instance, based on values passed in to the constructor as in the following example: #=== class A(object): def __init__(self, id): self._id = id

New style classes

2007-08-28 Thread Lamonte Harris
Whats the point of object? How do I actually use it. I'm not understanding correctly from the python site located: http://www.python.org/download/releases/2.2.3/descrintro/ class C(object): def __init__(self): self.__x = 0 def getx(self): return self.__x def setx(s

Re: New-style classes and special methods

2007-05-30 Thread Lenard Lindstrom
Raj B wrote: > > Yes, special methods populate the slots in the structures which Python > > uses to represent types. Objects/typeobject.c in the Python source > > distribution does the hard work, particularly in function type_new > > > > Thanks for that quick response. I am quite comfortable

Re: New-style classes and special methods

2007-05-30 Thread Alex Martelli
Raj B <[EMAIL PROTECTED]> wrote: > > Yes, special methods populate the slots in the structures which > Python > > uses to represent types. Objects/typeobject.c in the Python source > > distribution does the hard work, particularly in function type_new > > > > Thanks for that quick respons

Re: New-style classes and special methods

2007-05-30 Thread Raj B
> Yes, special methods populate the slots in the structures which Python > uses to represent types. Objects/typeobject.c in the Python source > distribution does the hard work, particularly in function type_new Thanks for that quick response. I am quite comfortable with C code and am try

Re: New-style classes and special methods

2007-05-30 Thread Alex Martelli
Raj B <[EMAIL PROTECTED]> wrote: > Hi > > My question is about how special methods are stored internally in > Python objects. > Consider a new-style class which implements special methods such as > __call__ and __new__ > > class C(type): > def __call__(...): > > > class

New-style classes and special methods

2007-05-30 Thread Raj B
Hi My question is about how special methods are stored internally in Python objects. Consider a new-style class which implements special methods such as __call__ and __new__ class C(type): def __call__(...): class B: __metaclass__ = C b= B() The ty

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread Steven Bethard
, everything will be new-style classes. In Python 2.X, it is extremely unlikely that anything will be upgraded to a new-style class. That would raise a number of backwards incompatibilities with relatively little benefit. STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread GiBo
Gabriel Genellina wrote: > En Mon, 19 Feb 2007 22:30:59 -0300, GiBo <[EMAIL PROTECTED]> escribió: > >> Is there a reason why some classes distributed with Python 2.5 are not >> new-style classes? For instance StringIO is apparently "old-style" class >>

Re: New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 22:30:59 -0300, GiBo <[EMAIL PROTECTED]> escribió: > Is there a reason why some classes distributed with Python 2.5 are not > new-style classes? For instance StringIO is apparently "old-style" class > i.e. not inherited from "object". Can I s

New-style classes (was Re: Checking for EOF in stream)

2007-02-19 Thread GiBo
son why some classes distributed with Python 2.5 are not new-style classes? For instance StringIO is apparently "old-style" class i.e. not inherited from "object". Can I somehow turn an existing old-style class to a new-style one? I tried for example: class MyStreamIO(Stre

Re: Are all classes new-style classes in 2.4+?

2006-12-31 Thread Steven D'Aprano
On Sun, 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez wrote: > Hi, > > This is probably a very basic question, but I've been playing with new > style classes, and I cannot see any difference in behavior when a > declare a class as: > > class NewStyleClass(object): >

Re: Are all classes new-style classes in 2.4+?

2006-12-31 Thread Felipe Almeida Lessa
On 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez <[EMAIL PROTECTED]> wrote: > I am using Python 2.4, and I was wondering if by default, all > classes are assumed to be derived from "object". This won't tell you advantages or disadvantages, but will show you that the default still is the old-style:

Re: Are all classes new-style classes in 2.4+?

2006-12-31 Thread Rene Fleschenberg
ctionality" seems to work the same at first glance (i.e. you don't need to learn alot of new syntax in order to switch from old-style to new-style classes). Play around with things like dir() and type() on old-style and new-style classes, and you will soon see differences. > If not, ca

Re: Are all classes new-style classes in 2.4+?

2006-12-31 Thread Bjoern Schliessmann
Isaac Rodriguez wrote: > This is probably a very basic question, but I've been playing with > new style classes, and I cannot see any difference in behavior > when a declare a class as: > > class NewStyleClass(object): > > or > > class NewStyleClass: Try mu

Are all classes new-style classes in 2.4+?

2006-12-31 Thread Isaac Rodriguez
Hi, This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or class NewStyleClass: I declare property members in both and it seems to work the exact same w

Re: module wide metaclass for new style classes

2006-12-17 Thread Daniel Nogradi
; > >> reg = [] > >>> def __metaclass__(name, bases, dict): > ... reg.append(name) > ... > >>> class A: pass > ... > >>> reg > ['A'] > >>> A is None > True # oops! > > > This would correctly print [ 'c1

Re: module wide metaclass for new style classes

2006-12-17 Thread Peter Otten
reg.append(name) ... >>> class A: pass ... >>> reg ['A'] >>> A is None True # oops! > This would correctly print [ 'c1', 'c2' ]. Now I would like to switch > to new style classes but replacing class c1: and class c2: by class > c1(obj

Re: module wide metaclass for new style classes

2006-12-16 Thread Gabriel Genellina
reg.append( name ) > return _meta > > reg = [ ] > __metaclass__ = meta( reg ) > > class c1: > pass > > class c2: > pass > > print reg > > This would correctly print [ 'c1', 'c2' ]. Now I would like to switch > to

module wide metaclass for new style classes

2006-12-16 Thread Daniel Nogradi
: pass print reg This would correctly print [ 'c1', 'c2' ]. Now I would like to switch to new style classes but replacing class c1: and class c2: by class c1(object): and class c2(object): doesn't work because the metaclass associated with object will be called and

Re: new-style classes, __hash__. is the documentation wrong?

2006-10-25 Thread Klaas
will be in the wrong hash bucket). > > now, with new style classes, the class will have __hash__, whatever i > do. (well, i assume i could play with __getattribute__...). There is a proposal to fix this, though I don't think we'll see it for a while. class CantHash(object):

new-style classes, __hash__. is the documentation wrong?

2006-10-25 Thread gabor
hat a key's hash value is immutable (if the object's hash value changes, it will be in the wrong hash bucket). ==== now, with new style classes, the class will have __hash__, whatever i do. (well, i assume i could play with __getattribute__...). so is that part of the documentation

Re: New-style classes slower than old-style classes? (Was: n-body problem at shootout.alioth.debian.org)

2006-10-08 Thread Peter Maas
Peter Maas schrieb: > 1 runs of nbody.py, time in sec Correction: 1 iterations of advance(). -- Regards/Gruesse, Peter Maas, Aachen E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64') -- http://mail.python.org/mailman/listinfo/python-list

Re: New-style classes slower than old-style classes? (Was: n-body problem at shootout.alioth.debian.org)

2006-10-08 Thread Peter Maas
Richard Jones wrote: > Giovanni Bajo wrote: [...] >> Anyway, this is a bug on its own I believe. I don't think new-style >> classes are meant to be 25% slower than old-style classes. Can any guru >> clarify this? > > Please try 2.5 - there's been signific

Re: New-style classes slower than old-style classes? (Was: n-body problem at shootout.alioth.debian.org)

2006-10-07 Thread Richard Jones
Ah yes. Years ago when I first saw this test it was still using new-style > classes. > > Anyway, this is a bug on its own I believe. I don't think new-style > classes are meant to be 25% slower than old-style classes. Can any guru > clarify this? Please try 2.5 - there'

New-style classes slower than old-style classes? (Was: n-body problem at shootout.alioth.debian.org)

2006-10-07 Thread Giovanni Bajo
using new-style classes. Anyway, this is a bug on its own I believe. I don't think new-style classes are meant to be 25% slower than old-style classes. Can any guru clarify this? -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic methods in new-style classes

2006-09-30 Thread bertgoos
The metaclass approach seems to be the one I was looking for. Thanks! Bert -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic methods in new-style classes

2006-09-29 Thread George Sakkis
Ben Cartwright wrote: > [EMAIL PROTECTED] wrote: > > Hey, I have the following code that has to send every command it > > receives to a list of backends. > > > I would like to write each method like: > > > > flush = multimethod() > > Here's one way, using a metaclass: Or if you don't mind a

Re: Automatic methods in new-style classes

2006-09-29 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > Hey, I have the following code that has to send every command it > receives to a list of backends. > I would like to write each method like: > > flush = multimethod() Here's one way, using a metaclass: class multimethod(object): def transform(self, attr):

Re: Automatic methods in new-style classes

2006-09-29 Thread Scott David Daniels
Scott David Daniels wrote: > > class Forwards(object): > > to_forward = set(['flush', 'read', 'write', 'close']) > > def __init__(self, backends): > self.backends = backends > > def forwarder(self, methodname): > def method(*args, **kwargs): > for b in se

Re: Automatic methods in new-style classes

2006-09-29 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > Hey, I want to send commands to a list of backends: How about something like: class Forwards(object): to_forward = set(['flush', 'read', 'write', 'close']) def __init__(self, backends): self.backends = backends def forwarder(self, methodname)

Re: Automatic methods in new-style classes

2006-09-29 Thread Peter Otten
self, backends): > self.backends = backends > > def flush(self): > for b in self.backends: > b.flush() > > def draw(self): > for b in self.backends: > b.draw() > > > I would like to write each method like: >

Automatic methods in new-style classes

2006-09-29 Thread bertgoos
for b in self.backends: b.flush() def draw(self): for b in self.backends: b.draw() I would like to write each method like: flush = multimethod() Is that possible using new-style classes? Bert -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating instances of untrusted new-style classes

2006-05-26 Thread greg
Michael Spencer wrote: > >>> class A(object): > ... > >>> b = object.__new__(A) Note that you'll need to be a bit cleverer if the class might be derived from some other built-in type: >>> class A(list): ... pass ... >>> b = object.__new__(A) Traceback (most recent call last): File "", li

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
gt; code (ignoring, for now, malicious code involving attribute access) as > > shown below. > > [snip my example] > > > > I'm not sure how to do the same for new-style classes, if it's at all > > possible to do from within Python. Is there any way to accompl

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Michael Spencer
quot; > ... >>>> f = Foo('spam','eggs','ham','bacon') # This would be in a restricted >>>> environment, though. > Your code didn't expect the Spanish inquisition! >>>> types.InstanceType(Foo, f.__dict__) # Thi

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
thout touching the actual old-style class code, but I'm not sure how, if it's possible, to do the same with new-style classes - Devan -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating instances of untrusted new-style classes

2006-05-25 Thread Ben Finney
"Devan L" <[EMAIL PROTECTED]> writes: > Is there any safe way to create an instance of an untrusted class Why are you instantiating classes you don't trust? > without consulting the class in any way? If you don't "consult the class", how can the instance be created properly? -- \ "It's

Creating instances of untrusted new-style classes

2006-05-25 Thread Devan L
#x27;ham','bacon') # This would be in a restricted >>> environment, though. Your code didn't expect the Spanish inquisition! >>> types.InstanceType(Foo, f.__dict__) # This wouldn't, but we never run that >>> code, anyways. <__main__.Foo ins

Re: Setting a module package to use new-style classes

2006-05-02 Thread Alex Martelli
Ben Finney <[EMAIL PROTECTED]> wrote: > "Panos Laganakos" <[EMAIL PROTECTED]> writes: > > > Is there a way to have a whole module package use the new-style > > classes, without having to specify it per module-file or even worse, > > per class defi

Re: Setting a module package to use new-style classes

2006-05-01 Thread Ben Finney
"Panos Laganakos" <[EMAIL PROTECTED]> writes: > Is there a way to have a whole module package use the new-style > classes, without having to specify it per module-file or even worse, > per class definition? TTBOMK, you do that with a single statement per module, bef

Setting a module package to use new-style classes

2006-05-01 Thread Panos Laganakos
Is there a way to have a whole module package use the new-style classes, without having to specify it per module-file or even worse, per class definition? Maybe by declaring the __metaclass__ in the module's __init__.py? -- http://mail.python.org/mailman/listinfo/python-list

Re: new-style classes and len method

2006-04-13 Thread bruno at modulix
Thomas Girod wrote: > It's alright I found where my mistake came from. I was misunderstanding > the meaning of "classmethod", thinking of it as an instance method. Given that 'instance methods' being most of the time attributes of the class object, such a confusion is not so surprising !-) -- br

Re: new-style classes and len method

2006-04-13 Thread bruno at modulix
Thomas Girod wrote: > Or maybe I'm mixing up what we call a "classmethod" with what we could > call an "instance method" ? > That's what I was about to point out !-) > class Data(list): > __slots__ = ["width", "height", "label"] > > def __init__(self,width,height,label=None): > l

Re: new-style classes and len method

2006-04-13 Thread Thomas Girod
It's alright I found where my mistake came from. I was misunderstanding the meaning of "classmethod", thinking of it as an instance method. -- http://mail.python.org/mailman/listinfo/python-list

Re: new-style classes and len method

2006-04-13 Thread Ben C
On 2006-04-13, Thomas Girod <[EMAIL PROTECTED]> wrote: > Hi there. > > I'm trying to use new-style classes, but there is something i'm > obviously missing > > here it is : > > class Data(list): > __slots__ = ["width", "height&qu

Re: new-style classes and len method

2006-04-13 Thread Paul McGuire
"Thomas Girod" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi there. > > I'm trying to use new-style classes, but there is something i'm > obviously missing > > here it is : > > class Data(list): > __slots__ = ["

Re: new-style classes and len method

2006-04-13 Thread Thomas Girod
Or maybe I'm mixing up what we call a "classmethod" with what we could call an "instance method" ? -- http://mail.python.org/mailman/listinfo/python-list

new-style classes and len method

2006-04-13 Thread Thomas Girod
Hi there. I'm trying to use new-style classes, but there is something i'm obviously missing here it is : class Data(list): __slots__ = ["width", "height", "label"] def __init__(self,width,height,label=None): list.__init__(self)

pickle and converting to new-style classes

2006-03-02 Thread [EMAIL PROTECTED]
Hi, I have a fairly sizable body of python code that I'm in the process of modernizing. One of the modernization steps is converting to use new-style classes, and this is leading to problems with pickle. What's happening is that part of the test suite for this code includes pickled in

Re: Mixing custom __setattr__ method and properties in new style classes

2006-02-08 Thread Scott David Daniels
L.C. Rees wrote: > Can custom __setattr__ methods and properties be mixed in new style > classes? > > I experimented with a new style class with both a custom __setattr__ > method and a property. Attributes controlled by the __setattr__ method > work fine. When I attempt

Re: Mixing custom __setattr__ method and properties in new style classes

2006-02-08 Thread Fredrik Lundh
"L.C. Rees" wrote: > This is the code for the property at the end of the class definition: > > def _settext(self, txt): > self._tree.text = txt > > def _gettext(self, txt): > return self._tree.text > > def _deltext(self, txt): > self._tree.text = '' > > text

Re: Mixing custom __setattr__ method and properties in new style classes

2006-02-08 Thread L.C. Rees
I see the error: the get and set properties are inverted. Now it works. -- http://mail.python.org/mailman/listinfo/python-list

Mixing custom __setattr__ method and properties in new style classes

2006-02-08 Thread L.C. Rees
Can custom __setattr__ methods and properties be mixed in new style classes? I experimented with a new style class with both a custom __setattr__ method and a property. Attributes controlled by the __setattr__ method work fine. When I attempt to set or get the property it raises the error

Re: new-style classes multiplication error message isn't veryinformative

2005-12-30 Thread Steven D'Aprano
On Fri, 30 Dec 2005 13:23:30 +, Jon Guyer wrote: > Steven D'Aprano REMOVETHIScyber.com.au> writes: > >> >> On Fri, 30 Dec 2005 03:47:30 +, Jon Guyer wrote: >> >> > We have a rather complicated class that, under certain circumstances, knows >> > that it cannot perform various arithmetic

  1   2   >