Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-23 Thread Thomas Lotze
Jim Fulton wrote: I would change it to just use getattr rather than hasattr. try: getattr(ob, name) except AttributeError: return False ... Given the controversy about our original proposal, I think I'll just implement Jim's suggestion. I'll do so as soon as possible. -- Thomas

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-23 Thread Marius Gedminas
On Thu, Oct 23, 2008 at 08:57:30AM +0200, Thomas Lotze wrote: Jim Fulton wrote: I would change it to just use getattr rather than hasattr. try: getattr(ob, name) except AttributeError: return False ... Given the controversy about our original proposal, I think I'll

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-19 Thread Dieter Maurer
Tres Seaver wrote at 2008-10-17 15:14 -0400: ... verifyObject/verifyClass is likely not to handle the following case correctly: class I(Interface): def m(...): ... class C(object): implements(I) m = property(lambda self: lambda ...: ...)

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Dieter Maurer
Christian Theune wrote at 2008-10-16 20:27 +0200: ... Then again, verifyObject is a *very* light way to spot simple errors. IMHO attributes and methods aren't that different in Python, as using both may result in exceptions. Using attributes (not computed one) does not result in exceptions.

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Thomas Lotze
Dieter Maurer [EMAIL PROTECTED] schrieb: And if the attribute is implemented by a property (of the class, i.e. the decriptor is on the metaclass), then the descriptors __get__ is called (in the same way as for verifyObject). Instance properties (descriptor on the class) may not define methods

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Dieter Maurer
Thomas Lotze wrote at 2008-10-16 20:57 +0200: Christian Theune [EMAIL PROTECTED] wrote: Arguably, the check for an attribute would be sufficient if it checked whether an attribute implementation is around -- either by a simple attribute value or a descriptor providing that. At this point, I

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dieter Maurer wrote: Thomas Lotze wrote at 2008-10-16 20:57 +0200: Christian Theune [EMAIL PROTECTED] wrote: Arguably, the check for an attribute would be sufficient if it checked whether an attribute implementation is around -- either by a

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Dieter Maurer
Thomas Lotze wrote at 2008-10-17 19:42 +0200: Dieter Maurer [EMAIL PROTECTED] schrieb: ... Instance properties (descriptor on the class) may not define methods (probably a bug). I don't understand what you're saying in that last sentence; can you elaborate? verifyObject/verifyClass is likely

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Thomas Lotze
Dieter Maurer [EMAIL PROTECTED] schrieb: verifyObject/verifyClass is likely not to handle the following case correctly: class I(Interface): def m(...): ... class C(object): implements(I) m = property(lambda self: lambda ...: ...) i.e. when

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dieter Maurer wrote: Thomas Lotze wrote at 2008-10-17 19:42 +0200: Dieter Maurer [EMAIL PROTECTED] schrieb: ... Instance properties (descriptor on the class) may not define methods (probably a bug). I don't understand what you're saying in that

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-17 Thread Thomas Lotze
Tres Seaver [EMAIL PROTECTED] schrieb: Dieter Maurer wrote: class C(object): implements(I) m = property(lambda self: lambda ...: ...) i.e. when a method (declared by the interface) is implemented by a property. Why would I want to do that, rather than using

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-16 Thread Dieter Maurer
Thomas Lotze wrote at 2008-10-15 20:55 +0200: Dieter Maurer [EMAIL PROTECTED] wrote: I fear your must describe your proposed change more precisely: Nothing to be afraid of here ;o) When your problem is the stated use case: verifyObject fails because something necessary for the interface

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-16 Thread Christian Theune
Hi, On Thu, 2008-10-16 at 18:45 +0200, Dieter Maurer wrote: I do not follow your argumentation: An attribute it not there because there is a descriptor, it is only there when the descriptor provides a value: I have seen descriptors in Zope3 that are only there to remove an attribute that

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-16 Thread Thomas Lotze
Christian Theune [EMAIL PROTECTED] wrote: Arguably, the check for an attribute would be sufficient if it checked whether an attribute implementation is around -- either by a simple attribute value or a descriptor providing that. At this point, I guess the outcome of the discussion depends on

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-15 Thread Jim Fulton
On Oct 15, 2008, at 3:27 AM, Thomas Lotze wrote: There has been a problem with zope.interface's verifyObject function that occurs in conjunction with Python properties: when verifyObject checks for the presence of an object's attribute, it does so by using hasattr() which in turn tries a

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-15 Thread Thomas Lotze
Jim Fulton [EMAIL PROTECTED] wrote: I would change it to just use getattr rather than hasattr. try: getattr(ob, name) except AttributeError: return False ... This doesn't handle the case that the attribute exists as a property but raises an AttributeError when trying to produce

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-15 Thread Philipp von Weitershausen
Thomas Lotze wrote: Jim Fulton [EMAIL PROTECTED] wrote: I would change it to just use getattr rather than hasattr. try: getattr(ob, name) except AttributeError: return False ... This doesn't handle the case that the attribute exists as a property but raises an AttributeError

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-15 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thomas Lotze wrote: Jim Fulton [EMAIL PROTECTED] wrote: I would change it to just use getattr rather than hasattr. try: getattr(ob, name) except AttributeError: return False ... This doesn't handle the case that the attribute

Re: [Zope-dev] zope.interface: verifyObject vs properties

2008-10-15 Thread Dieter Maurer
Thomas Lotze wrote at 2008-10-15 09:27 +0200: There has been a problem with zope.interface's verifyObject function that occurs in conjunction with Python properties: when verifyObject checks for the presence of an object's attribute, it does so by using hasattr() which in turn tries a getattr()