[Python-projects] PyLint: False positive "<type> has no '<method>' member"

Maarten ter Huurne maarten.ter.huurne at philips.com
Fri Nov 24 15:20:25 CET 2006


Hi,

If I run PyLint on the following program:
===
def radixSort(elements, keyFuncs):
        sortList = None
        for keyFunc in reversed(keyFuncs):
                if sortList is None:
                        sortList = sorted(elements, key = keyFunc)
                else:
                        sortList.sort(key = keyFunc)
        return sortList
===
It issues this warning:
===
E1101:  7:radixSort: Instance of 'None' has no 'sort' member
===

I think this is a problem of the type inference. Even if it doesn't 
understand that in the "else" clause of "if sortList is None" it is 
guaranteed that "sortList" is not None, it should still know that 
"sortList" can be either None or a list, since "sorted" always returns a 
list (see the assignment in line 5).

(For those interested: the reason for treating the least significant key 
differently is that "elements" is not necessarily a list: it can be a 
generator or another kind of sequence.)

PyLint 0.12.2, astng 0.16.3, common 0.21.0.

Bye,
                Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20061124/b6ac04c9/attachment.html 


More information about the Python-Projects mailing list