[Chicago] Prevent access to method as attribute

Brian Ray brianhray at gmail.com
Tue Oct 16 18:58:36 CEST 2012


Question came up from a colleague:

I wonder, if there is a simple way in Python to add a hook to class that
makes sure methods don't not get called as attributes.

class A:
    def isValid(self):
           return False


if A().isValid:
    print 'Always True'



I had some wacky and wild thoughts about subclassing something to
check each and every call and using inspect module to see how it was
called. Generally, I know it is the callers responsibility to know
what they are doing. We are all responsible adults here, correct?



-- 
Brian Ray
@brianray
(773) 669-7717


More information about the Chicago mailing list