[Python-projects] pylint: false undefined variable error in lambda function

J Robert Ray jrobertray at gmail.com
Wed May 27 07:42:30 CEST 2009


Sorry, I could not find a way to register on the logilab site to
submit this as a ticket.

Here is a short demonstration program that shows that a lambda
function's parameter is flagged as undefined if the lambda function is
an argument to a decorator function.

I have taken care so that the program has no other errors with the
default configuration.

#!/bin/env python

"""Demonstrate false undefined variable for lambda functions."""

def decorator(expr):
   """Function returning decorator."""
   def func(function):
       """Pass-thru decorator."""
       return function
   # use expr
   expr(0)
   return func

# this lambda is flagged
# E0602:  16:main.<lambda>: Undefined variable 'x'
@decorator(lambda x: x > 0)
def main():
   """Dummy function."""
   # this one is not flagged
   decorator(lambda y: y > 0)

if __name__ == "__main__":
   main()


************* Module lambda
E0602: 16:main.<lambda>: Undefined variable 'x'


Report
======
9 statements analysed.

> pylint --version
pylint 0.18.0,
astng 0.19.0, common 0.40.0
Python 2.4.1 (#1, Feb  1 2006, 14:47:49)
[GCC 3.4.3 20050227 (Red Hat 3.4.3-22.1)]


More information about the Python-Projects mailing list