Just kidding.

def redefined_by_decorator(node):
    """return True if the object is a method redefined via decorator.

    For example:
        @property
        def x(self): return self._x
        @x.setter
        def x(self, value): self._x = value
    """
    if node.decorators:
        for decorator in node.decorators.nodes:
            if (isinstance(decorator, astng.Getattr) and
                not isinstance(node, astng.Getattr) and
                decorator.expr.name == node.name):
                return True
    return False


On Fri, Aug 17, 2012 at 3:18 PM, JT Olds <jto...@xnet5.com> wrote:
> I have no idea if this interpretation is right, but here's what I
> think is going on?
>
> in pylint/checkers/base.py, there's a redefined_by_decorator method, like
>
> def redefined_by_decorator(node):
>     if node.decorators:
>         for decorator in node.decorators.nodes:
>             if (isinstance(decorator, astng.Getattr) and
>                 decorator.expr.name == node.name):
>                 return True
>     return False
>
> I think the "and" should be an "or".
>
> True?
>
> On Fri, Aug 17, 2012 at 3:06 PM, JT Olds <jto...@xnet5.com> wrote:
>> Hey all,
>>
>> I'm getting a weird error from pylint. I've reduced the code that
>> makes pylint choke to a small test case. When I run pylint on
>>
>> class Thing2(object):
>>     def decorator(self, method):
>>         def wrapper(*args, **kwargs):
>>             return method(*args, **kwargs)
>>         return wrapper
>>
>> class Thing1(object):
>>     def __getattr__(self, name):
>>         return Thing2()
>>
>> thing = Thing1()
>>
>> @thing.my_param.decorator
>> def test():
>>     print "hi"
>>
>> I get:
>>
>> Traceback (most recent call last):
>>   File "/home/jt/.virtualenvs/default/bin/pylint", line 4, in <module>
>>     lint.Run(sys.argv[1:])
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/lint.py",
>> line 879, in __init__
>>     linter.check(args)
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/lint.py",
>> line 502, in check
>>     self.check_astng_module(astng, walker, rawcheckers)
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/lint.py",
>> line 574, in check_astng_module
>>     walker.walk(astng)
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/utils.py",
>> line 528, in walk
>>     self.walk(child)
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/utils.py",
>> line 525, in walk
>>     cb(astng)
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/checkers/base.py",
>> line 161, in visit_function
>>     if not redefined_by_decorator(node):
>>   File 
>> "/home/jt/.virtualenvs/default/local/lib/python2.7/site-packages/pylint/checkers/base.py",
>> line 116, in redefined_by_decorator
>>     decorator.expr.name == node.name):
>> AttributeError: 'Getattr' object has no attribute 'name'
>>
>> Any ideas?
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to