diff options
Diffstat (limited to 'pylint/test/input/func_deprecated_lambda_py_30.py')
-rw-r--r-- | pylint/test/input/func_deprecated_lambda_py_30.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pylint/test/input/func_deprecated_lambda_py_30.py b/pylint/test/input/func_deprecated_lambda_py_30.py new file mode 100644 index 0000000..74b3241 --- /dev/null +++ b/pylint/test/input/func_deprecated_lambda_py_30.py @@ -0,0 +1,24 @@ +# pylint: disable=missing-docstring,bad-builtin,invalid-name,no-absolute-import +__revision__ = "$Id$" + +import functools + +# Don't do this, use a comprehension instead. +assert map(lambda x: x*2, [1, 2, 3]) == [2, 4, 6] + +assert filter(lambda x: x != 1, [1, 2, 3]) == [2, 3] + +# It's still ok to use map and filter with anything but an inline lambda. +double = lambda x: x * 2 +assert map(double, [1, 2, 3]) == [2, 4, 6] + +# It's also ok to pass lambdas to other functions. +assert functools.reduce(lambda x, y: x * y, [1, 2, 3, 4]) == 24 + +# Or to a undefined function or one with varargs +def f(*a): + return len(a) + +f(lambda x, y: x + y, [1, 2, 3]) + +undefined_function(lambda: 2) # pylint: disable=undefined-variable |