pylint treat lamba at class level different from a function in python, they are the same, consider this code: """ Test lambda in a class """
import pprint
class Test:
""" lambda needs Test instance as first argument """
lam = lambda self, icon: pprint.pprint([self, icon])
def test(self):
""" this works at least in python 2.4 through 2.7 """
self.lam("an icon")
if __name__ == "__main__":
Test().test()
In python (tested 2.4~2.7), Test().test and Test().lam are bound methods and thus Test().test() and Test().lam("anicon") are valid; while Test.test() and Test.lam() are invalid (need instance of Test as first argument). Pylint doesn't seem to know this w.r.t. lambdas. It seems Pylint think that lam = at class level is just a member variable, that is treats lam = lambda: ... same as if it was lam = 123. | |
| priority | normal |
|---|---|
| type | bug |
| appeared in | <not specified> |
| done in | <not specified> |
| closed by | <not specified> |


#76910 pip install errors/warnings
Comments
-
2011/09/23 11:07 | reply to this comment
(add comment)I would be tempted to flag this usage of lambda as an abuse and poor style.