I have two classes: class Person: .... class ZPerson(Person, ZopeClasses....): .... in Person 'n override __gt__, __lt__, and some others.
p1 = Person() p2 = Person() p1.age = 20 p2.age = 30 p2 > p1 True
this doesn't work for the derived Zope class:
p1 = ZPerson() #ok, I create this in the "proper" zope way and #later retrieve it, but you get the idea p2 = ZPerson() p1.age = 20 p2.age = 30 p2 > p1 False p2.__gt__(p1) True
For some reason my __gt__ is not used when using the > operator. If called explicitly, it works properly. Any ideas? Etienne
It might be an order of inheritance issue. Try changing the order in which you declare the parent classes: class ZPerson(ZopeClasseses, ..., Person): .... --Sean
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org]On Behalf Of Etienne Labuschagne Sent: Tuesday, October 26, 2004 3:05 AM To: zope@zope.org Subject: [Zope] Operator overriding not working with Zope class.
I have two classes:
class Person: ....
class ZPerson(Person, ZopeClasses....): ....
in Person 'n override __gt__, __lt__, and some others.
p1 = Person() p2 = Person() p1.age = 20 p2.age = 30 p2 > p1 True
this doesn't work for the derived Zope class:
p1 = ZPerson() #ok, I create this in the "proper" zope way and #later retrieve it, but you get the idea p2 = ZPerson() p1.age = 20 p2.age = 30 p2 > p1 False p2.__gt__(p1) True
For some reason my __gt__ is not used when using the > operator. If called explicitly, it works properly.
Any ideas?
Etienne _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Sean Hastings wrote: I don't think it is that as it is resolved correctly when using the __gt__ method explicitly. p2.__gt__(p1) works fine, it is p2 > p1 that doesn't work. Doing a inspect.getmro in the object's class also gives me (ZPerson, Person, ....) so it seems as if Person is second in the resolution order. Since there is no __gt__ method defined in ZPerson, it should then resolve to Person's __gt__. Etienne
It might be an order of inheritance issue. Try changing the order in which you declare the parent classes:
class ZPerson(ZopeClasseses, ..., Person): ....
--Sean
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org]On Behalf Of Etienne Labuschagne Sent: Tuesday, October 26, 2004 3:05 AM To: zope@zope.org Subject: [Zope] Operator overriding not working with Zope class.
I have two classes:
class Person: ....
class ZPerson(Person, ZopeClasses....): ....
in Person 'n override __gt__, __lt__, and some others.
p1 = Person() p2 = Person() p1.age = 20 p2.age = 30 p2 > p1 True
this doesn't work for the derived Zope class:
p1 = ZPerson() #ok, I create this in the "proper" zope way and #later retrieve it, but you get the idea p2 = ZPerson() p1.age = 20 p2.age = 30 p2 > p1 False p2.__gt__(p1) True
For some reason my __gt__ is not used when using the > operator. If called explicitly, it works properly.
Any ideas?
Etienne _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hi, Am Di, den 26.10.2004 schrieb Etienne Labuschagne um 10:39:
Sean Hastings wrote:
I don't think it is that as it is resolved correctly when using the __gt__ method explicitly. p2.__gt__(p1) works fine, it is p2 > p1 that doesn't work. Doing a inspect.getmro in the object's class also gives me (ZPerson, Person, ....) so it seems as if Person is second in the resolution order. Since there is no __gt__ method defined in ZPerson, it should then resolve to Person's __gt__.
Without much research I can imagine this is because of the Zope classes you use are not new style classes and therefore dont use all the new interface. I could as well be wrong but maybe if you try zope 2.8 or 3.x it could be different. Regards Tino
Hi, I'd be surprised if that was the case as I have never explicitly declared the "pure" Python class as a new-style class (ie. inherited from object). Etienne Tino Wildenhain wrote:
Hi,
Am Di, den 26.10.2004 schrieb Etienne Labuschagne um 10:39:
Sean Hastings wrote:
I don't think it is that as it is resolved correctly when using the __gt__ method explicitly. p2.__gt__(p1) works fine, it is p2 > p1 that doesn't work. Doing a inspect.getmro in the object's class also gives me (ZPerson, Person, ....) so it seems as if Person is second in the resolution order. Since there is no __gt__ method defined in ZPerson, it should then resolve to Person's __gt__.
Without much research I can imagine this is because of the Zope classes you use are not new style classes and therefore dont use all the new interface. I could as well be wrong but maybe if you try zope 2.8 or 3.x it could be different.
Regards Tino
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Etienne Labuschagne -
Etienne Labuschagne -
Sean Hastings -
Tino Wildenhain