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. """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()
gives ************* Module lambda E0602: 16:main.<lambda>: Undefined variable 'x' > 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)] | |
| priority | important |
|---|---|
| type | bug |
| appeared in | <not specified> |
| done in | 0.18.1 |
| load | 0.500 |
| load left | 0.000 |
| closed by | <not specified> |



#9188 Avoidable W0631