diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2019-07-21 10:56:00 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-09-10 11:20:16 +0200 |
commit | 997d9d1ec72fce84903da4784ac56fbe30e6da1e (patch) | |
tree | 9a0ddd3ba0975e045e408d9793cce096ecaeaa75 /tests/functional/d/deprecated_lambda.py | |
parent | 676ec55ff9d8f10e52b740a57e4e62a3255d6709 (diff) | |
download | pylint-git-997d9d1ec72fce84903da4784ac56fbe30e6da1e.tar.gz |
[functional tests] Rename example_functional_tests.py => e/example_functional_tests.py
Permit to navigate in the functional tests easier.
Diffstat (limited to 'tests/functional/d/deprecated_lambda.py')
-rw-r--r-- | tests/functional/d/deprecated_lambda.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/functional/d/deprecated_lambda.py b/tests/functional/d/deprecated_lambda.py new file mode 100644 index 000000000..92a2e84ab --- /dev/null +++ b/tests/functional/d/deprecated_lambda.py @@ -0,0 +1,23 @@ +# pylint: disable=missing-docstring,invalid-name,no-absolute-import + +import functools + +# Don't do this, use a comprehension instead. +assert map(lambda x: x*2, [1, 2, 3]) == [2, 4, 6] # [deprecated-lambda] + +assert filter(lambda x: x != 1, [1, 2, 3]) == [2, 3] # [deprecated-lambda] + +# 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 an 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 |