[Python-projects] pylint/astng feature request: namedtuple support

Maarten ter Huurne maarten at treewalker.org
Thu Mar 26 01:33:19 CET 2009


On Thursday 26 March 2009, Vincent Legoll wrote:

> pylint was failing to detect such cases on meld code (meld.sf.net)
>
> from misc.py:
>
> class struct(object):
>     """Similar to a dictionary except that members may be accessed as
> s.member.
>
>     Usage:
>     s = struct(a=10, b=20, d={"cat":"dog"} )
>     print s.a + s.b
>     """
>     def __init__(self, **args):
>         self.__dict__.update(args)
>     def __repr__(self):
>         r = ["<"]
>         for i in self.__dict__.keys():
>             r.append("%s=%s" % (i, getattr(self,i)))
>         r.append(">\n")
>         return " ".join(r)
>     def __cmp__(self, other):
>         return cmp(self.__dict__, other.__dict__)
>
> uses of instances of this class are flagged as errors

This is indeed a similar situation. However, I think it might be very 
difficult for astng to actually understand the code above.

In the case of namedtuple(), it is part of the standard library, so support 
for this particular function could be hardcoded, making it much easier to 
implement.

Bye,
		Maarten



More information about the Python-Projects mailing list