[Chicago] Prevent access to method as attribute

Cezar Jenkins emperorcezar at gmail.com
Tue Oct 16 19:39:51 CEST 2012


On Tuesday, October 16, 2012 at 11:58 AM, Brian Ray 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?
> 
Correct. It's one of the decision Guido made when designing Python and has stood behind it since. It is the idea that arbitrary restrictions shouldn't be enforced at the language level. Thus the reason for there not being, and probably never will be, language level enforcement of public/protected/private what not.

I'm sure most of you knew this, but it's something worth mentioning for those newer to Python who might wonder who those aren't in the language.

 
> 
> 
> 
> -- 
> Brian Ray
> @brianray
> (773) 669-7717
> _______________________________________________
> Chicago mailing list
> Chicago at python.org (mailto:Chicago at python.org)
> http://mail.python.org/mailman/listinfo/chicago





More information about the Chicago mailing list