File tree Expand file tree Collapse file tree 7 files changed +101
-2
lines changed
2/query-tests/Expressions
3/query-tests/Expressions/UseofApply
query-tests/Expressions/general Expand file tree Collapse file tree 7 files changed +101
-2
lines changed Original file line number Diff line number Diff line change 1010 */
1111
1212import python
13+ private import semmle.python.types.Builtins
1314
1415from CallNode call , ControlFlowNode func
15- where
16- major_version ( ) = 2 and call .getFunction ( ) = func and func .refersTo ( Object:: builtin ( "apply" ) )
16+ where major_version ( ) = 2 and call .getFunction ( ) = func and func .pointsTo ( Value:: named ( "apply" ) )
1717select call , "Call to the obsolete builtin function 'apply'."
Original file line number Diff line number Diff line change 1+ | UseofApply.py:19:3:19:17 | ControlFlowNode for apply() | Call to the obsolete builtin function 'apply'. |
12| expressions_test.py:3:5:3:21 | ControlFlowNode for apply() | Call to the obsolete builtin function 'apply'. |
Original file line number Diff line number Diff line change 1+ #### UseofApply.ql
2+
3+ # Use of the builtin function `apply` is generally considered bad now that the
4+ # ability to destructure lists of arguments is possible, but we should not flag
5+ # cases where the function is merely named `apply` rather than being the actual
6+ # builtin `apply` function.
7+
8+ def useofapply ():
9+
10+ def foo ():
11+ pass
12+
13+
14+
15+ # Positive Cases
16+
17+ # This use of `apply` is a reference to the builtin function and so SHOULD be
18+ # caught by the query.
19+ apply (foo , [1 ])
20+
21+
22+
23+ # Negative Cases
24+
25+ # This use of `apply` is a reference to the locally defined function inside of
26+ # `local`, and so SHOULD NOT be caught by the query.
27+ def local ():
28+ def apply (f ):
29+ pass
30+ apply (foo )([1 ])
Original file line number Diff line number Diff line change 1+ #### UseofApply.ql
2+
3+ # Use of the builtin function `apply` is generally considered bad now that the
4+ # ability to destructure lists of arguments is possible, but we should not flag
5+ # cases where the function is merely named `apply` rather than being the actual
6+ # builtin `apply` function.
7+
8+ def useofapply ():
9+
10+ def foo ():
11+ pass
12+
13+
14+
15+ # Positive Cases
16+
17+ # This use of `apply` is a reference to the builtin function and so SHOULD be
18+ # caught by the query.
19+ apply (foo , [1 ])
20+
21+
22+
23+ # Negative Cases
24+
25+ # This use of `apply` is a reference to the locally defined function inside of
26+ # `local`, and so SHOULD NOT be caught by the query.
27+ def local ():
28+ def apply (f ):
29+ pass
30+ apply (foo )([1 ])
Original file line number Diff line number Diff line change 1+ Expressions/UseofApply.ql
Original file line number Diff line number Diff line change @@ -242,3 +242,40 @@ def func():
242242
243243def mpt_arg (d = MappingProxyType ({})):
244244 return 1 in d
245+
246+
247+
248+
249+
250+
251+
252+ #### UseofApply.ql
253+
254+ # Use of the builtin function `apply` is generally considered bad now that the
255+ # ability to destructure lists of arguments is possible, but we should not flag
256+ # cases where the function is merely named `apply` rather than being the actual
257+ # builtin `apply` function.
258+
259+ def useofapply ():
260+
261+ def foo ():
262+ pass
263+
264+
265+
266+ # Positive Cases
267+
268+ # This use of `apply` is a reference to the builtin function and so SHOULD be
269+ # caught by the query.
270+ apply (foo , [1 ])
271+
272+
273+
274+ # Negative Cases
275+
276+ # This use of `apply` is a reference to the locally defined function inside of
277+ # `local`, and so SHOULD NOT be caught by the query.
278+ def local ():
279+ def apply (f ):
280+ pass
281+ apply (foo )([1 ])
You can’t perform that action at this time.
0 commit comments