<br><br><div class="gmail_quote">On Tue, Oct 16, 2012 at 9:58 AM, Brian Ray <span dir="ltr"><<a href="mailto:brianhray@gmail.com" target="_blank">brianhray@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Question came up from a colleague:<br>
<br>
I wonder, if there is a simple way in Python to add a hook to class that<br>
makes sure methods don't not get called as attributes.<br>
<br>
class A:<br>
def isValid(self):<br>
return False<br>
<br>
<br>
if A().isValid:<br>
print 'Always True'<br>
<br>
<br>
<br>
I had some wacky and wild thoughts about subclassing something to<br>
check each and every call and using inspect module to see how it was<br>
called. Generally, I know it is the callers responsibility to know<br>
what they are doing. We are all responsible adults here, correct?<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Brian Ray<br>
@brianray<br>
<a href="tel:%28773%29%20669-7717" value="+17736697717">(773) 669-7717</a><br>
_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
</font></span></blockquote></div><br>Not a sane one know. The closest you could do would be to have a descriptor that kept a flag on itself marking whether it was called, and then have an __del__ that raised an error if it wasn't called.<div>
<br></div><div>Like I said, really not sane.</div><div><br></div><div>Alex<br clear="all"><div><br></div>-- <br>"I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)<br>
"The people's good is the highest law." -- Cicero<br><br>
</div>