Re: ObjectWrapper subclasses always callable
PJ Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> Wed, 23 May 2012 14:01:11 -0400
| Newsgroups | gmane.comp.python.peak |
|---|---|
| Message-ID | <CALeMXf7rgMbxZO=tToK1nWeK6wMm6CdDCjAq7NyCNjtSpBm=zg@mail.gmail.com> |
--===============0553118604== Content-Type: multipart/alternative; boundary=20cf3071c6f0a0818404c0b7ebcd --20cf3071c6f0a0818404c0b7ebcd Content-Type: text/plain; charset=ISO-8859-1 On Wed, May 23, 2012 at 11:25 AM, Marcin Tustin <[email protected]>wrote: > Python 2.7.2 > > > On Wed, May 23, 2012 at 4:23 PM, PJ Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> wrote: > >> >> On May 23, 2012 10:39 AM, "Marcin Tustin" <[email protected]> >> wrote: >> > >> > I've found that instances of ObjectWrapper (and any subclasses) are >> always callable (the callable function returns True), notwithstanding that >> the __subject__ is not callable. Is there a way to remedy this? >> > >> > I've tried deleting the __call__ method, creating empty slots, creating >> my own call method, then trying to delete, using del or delattr on the >> subclass object, and creating a custom __getattribute__, all to no avail. >> >> Which Python version are you using? >> > > Okay, I've verified that this happens all the way back to 2.3, so that's not it. (I think that maybe Python 3 uses hasattr(__call__) as its callable() implementation, but I'm not sure.) It looks like the only way for me to fix this is with a major revision: change the base classes to not have a __call__ slot, and dynamically change type at runtime to a subclass with a __call__ slot, if and only if their subject is callable... and to somehow change if the subject changes. (Not really sure how that's going to work.) What's the use case for this? What code is using callable(), and can you convince its author to use hasattr instead? ;-) --20cf3071c6f0a0818404c0b7ebcd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, May 23, 2012 at 11:25 AM, Marcin Tustin <span dir=3D"ltr"><<a hr= ef=3D"mailto:[email protected]" target=3D"_blank">marcin.tustin@gmail= .com</a>></span> wrote:<br><div class=3D"gmail_quote"><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex"> Python 2.7.2<div class=3D"HOEnZb"><div class=3D"h5"><br><br><div class=3D"g= mail_quote">On Wed, May 23, 2012 at 4:23 PM, PJ Eby <span dir=3D"ltr"><<= a href=3D"mailto:pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]" target=3D"_blank">pje@telecommunity= .com</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> <div><p><br> On May 23, 2012 10:39 AM, "Marcin Tustin" <<a href=3D"mailto:m= [email protected]" target=3D"_blank">[email protected]</a>> w= rote:<br> ><br> > I've found that instances of ObjectWrapper (and any subclasses) ar= e always callable (the callable function returns True), notwithstanding tha= t the __subject__ is not callable. Is there a way to remedy this?<br> ><br> > I've tried deleting the __call__ method, creating empty slots, cre= ating my own call method, then trying to delete, using del or delattr on th= e subclass object, and creating a custom __getattribute__, all to no avail.= =A0</p> </div><p>Which Python version are you using?</p> </blockquote></div><br></div></div></blockquote></div>Okay, I've verifi= ed that this happens all the way back to 2.3, so that's not it.=A0 (I t= hink that maybe Python 3 uses hasattr(__call__) as its callable() implement= ation, but I'm not sure.)<br> <br>It looks like the only way for me to fix this is with a major revision:= change the base classes to not have a __call__ slot, and dynamically chang= e type at runtime to a subclass with a __call__ slot, if and only if their = subject is callable...=A0 and to somehow change if the subject changes.=A0 = (Not really sure how that's going to work.)<br> <br>What's the use case for this?=A0 What code is using callable(), and= can you convince its author to use hasattr instead?=A0 ;-)<br><br><br> --20cf3071c6f0a0818404c0b7ebcd-- --===============0553118604== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ PEAK mailing list [email protected] http://www.eby-sarna.com/mailman/listinfo/peak --===============0553118604==--