[Chicago] Prevent access to method as attribute
djuber at gmail.com
Tue Oct 16 19:10:09 CEST 2012
Well, I for one am guilty of doing just this to objects. Switching between smalltalk and python gives me a headache when sending unary messages and calling functions without arguments doesn't line up right in my head.
If there is a good, clean, global way to do this, I'd love to see it. Maybe if 'if' were stricter about boolean values (expecting True), it would be a simple idea, but that's a language and idiom shift everywhere else. Short of that, just checking to see if the return value is a function rather than a value (I know, a function _is_ a value), perhaps in an aware editor, is a better way to catch this type of mistake.
On Oct 16, 2012, at 11:58 AM, Brian Ray <brianhray at gmail.com> wrote:
> 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
> (773) 669-7717
> Chicago mailing list
> Chicago at python.org
More information about the Chicago