Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / deprecated_lambda.py @ 745

History | View | Annotate | Download (734 Bytes)

1
# pylint: disable=missing-docstring,bad-builtin,invalid-name,no-absolute-import
2

    
3
import functools
4

    
5
# Don't do this, use a comprehension instead.
6
assert map(lambda x: x*2, [1, 2, 3]) == [2, 4, 6] # [deprecated-lambda]
7

    
8
assert filter(lambda x: x != 1, [1, 2, 3]) == [2, 3] # [deprecated-lambda]
9

    
10
# It's still ok to use map and filter with anything but an inline lambda.
11
double = lambda x: x * 2
12
assert map(double, [1, 2, 3]) == [2, 4, 6]
13

    
14
# It's also ok to pass lambdas to other functions.
15
assert functools.reduce(lambda x, y: x * y, [1, 2, 3, 4]) == 24
16

    
17
# Or to a undefined function or one with varargs
18
def f(*a):
19
    return len(a)
20

    
21
f(lambda x, y: x + y, [1, 2, 3])
22

    
23
undefined_function(lambda: 2)  # pylint: disable=undefined-variable