[Chicago] Prevent access to method as attribute

Brian Ray brianhray at gmail.com
Thu Oct 18 14:45:33 CEST 2012


That would cool if a syntax check warned about access an attribute
where a method call was what may have been intended. PyLint does not
do this as far as I am aware. Perhaps there is some other syntax
chacker?

On Thu, Oct 18, 2012 at 7:11 AM, Brantley Harris <deadwisdom at gmail.com> wrote:
> This seems like something that should be done at testing or some syntax
> checking stage, like PyLint.  Sure you can solve it this way, it's in fact
> rather interesting and clever, but it adds a whole lot of complexity for
> little gain.
>
> Always Be Testin'
>
> On Wed, Oct 17, 2012 at 7:39 AM, Brian Ray <brianhray at gmail.com> wrote:
>>
>> This is very cool and clean too. Dare I say Pythonic? Good job
>> everyone and thanks!
>>
>> On Wed, Oct 17, 2012 at 6:41 AM, Ken Schutte <kenschutte at gmail.com> wrote:
>> > Along similar lines, you could try this:
>> >
>> >
>> > class notAttribute(object):
>> >     def __init__(self, func):
>> >         self.func = func
>> >
>> >     def __get__(self, obj, type = None):
>> >         return self.__class__(self.func.__get__(obj, type))
>> >
>> >     def __nonzero__(self):
>> >         raise Exception("Don't check me as an attribute!  Call me
>> > first!")
>> >
>> >     def __call__(self,*a,**kw):
>> >         return self.func(*a,**kw)
>> >
>> >
>> > Usage:
>> >
>> > class A(object):
>> >
>> >     @notAttribute
>> >     def isValid(self):
>> >         return False
>> >
>> >
>> > a = A()
>> >
>> > try:
>> >     if a.isValid:
>> >         print "(1) valid"
>> >     else:
>> >         print "(1) not valid"
>> > except Exception, e:
>> >     print "ERROR:", e
>> >
>> > if a.isValid():
>> >     print "(2) valid"
>> > else:
>> >     print "(2) not valid"
>> >
>>
>> --
>> Brian Ray
>> @brianray
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
>
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>



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


More information about the Chicago mailing list