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 / unnecessary_lambda.py @ 745

History | View | Annotate | Download (1.72 KB)

1
# pylint: disable=undefined-variable
2
"""test suspicious lambda expressions
3
"""
4

    
5
__revision__ = ''
6

    
7
# Some simple examples of the most commonly encountered forms.
8
# +1: [unnecessary-lambda]
9
_ = lambda: list()  # replaceable with "list"
10
# +1: [unnecessary-lambda]
11
_ = lambda x: hash(x)  # replaceable with "hash"
12
# +1: [unnecessary-lambda]
13
_ = lambda x, y: min(x, y)  # replaceable with "min"
14

    
15
# A function that can take any arguments given to it.
16
_ANYARGS = lambda *args, **kwargs: 'completely arbitrary return value'
17

    
18
# Some more complex forms of unnecessary lambda expressions.
19
# +1: [unnecessary-lambda]
20
_ = lambda *args: _ANYARGS(*args)
21
# +1: [unnecessary-lambda]
22
_ = lambda **kwargs: _ANYARGS(**kwargs)
23
# +1: [unnecessary-lambda]
24
_ = lambda *args, **kwargs: _ANYARGS(*args, **kwargs)
25
# +1: [unnecessary-lambda]
26
_ = lambda x, y, z, *args, **kwargs: _ANYARGS(x, y, z, *args, **kwargs)
27

    
28
# Lambdas that are *not* unnecessary and should *not* trigger warnings.
29
_ = lambda x: x
30
_ = lambda x: x()
31
_ = lambda x=4: hash(x)
32
_ = lambda x, y: list(range(y, x))
33
_ = lambda x: list(range(5, x))
34
_ = lambda x, y: list(range(x, 5))
35
_ = lambda x, y, z: x.y(z)
36
_ = lambda: 5
37
_ = lambda **kwargs: _ANYARGS()
38
_ = lambda **kwargs: _ANYARGS(**dict([('three', 3)]))
39
_ = lambda **kwargs: _ANYARGS(**{'three': 3})
40
_ = lambda dict_arg, **kwargs: _ANYARGS(kwargs, **dict_arg)
41
_ = lambda *args: _ANYARGS()
42
_ = lambda *args: _ANYARGS(*list([3, 4]))
43
_ = lambda *args: _ANYARGS(*[3, 4])
44
_ = lambda list_arg, *args: _ANYARGS(args, *list_arg)
45
_ = lambda: _ANYARGS(*[3])
46
_ = lambda: _ANYARGS(**{'three': 3})
47
_ = lambda: _ANYARGS(*[3], **{'three': 3})
48
_ = lambda: _ANYARGS(func=42)
49

    
50
# Don't warn about this.
51
_ = lambda: code().analysis()