Skip to content

Commit 71308d9

Browse files
authored
SONARPY-1756 exclude function from the built-in shadowing check (#2023)
1 parent cacf1e6 commit 71308d9

File tree

3 files changed

+8
-97
lines changed

3 files changed

+8
-97
lines changed

its/ruling/src/test/resources/expected/python-S5806.json

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,9 @@
284284
546,
285285
555
286286
],
287-
"project:django-2.2.3/django/contrib/gis/db/models/functions.py": [
288-
54,
289-
248,
290-
342,
291-
356,
292-
391
293-
],
294287
"project:django-2.2.3/django/contrib/messages/storage/cookie.py": [
295288
155
296289
],
297-
"project:django-2.2.3/django/contrib/postgres/search.py": [
298-
158
299-
],
300290
"project:django-2.2.3/django/contrib/sessions/backends/base.py": [
301291
96,
302292
103
@@ -340,9 +330,6 @@
340330
"project:django-2.2.3/django/utils/http.py": [
341331
184
342332
],
343-
"project:django-2.2.3/django/views/debug.py": [
344-
417
345-
],
346333
"project:django-2.2.3/django/views/generic/dates.py": [
347334
618
348335
],
@@ -374,26 +361,20 @@
374361
],
375362
"project:mypy-0.782/mypy/checker.py": [
376363
2728,
377-
2996,
378364
4826
379365
],
380366
"project:mypy-0.782/mypy/checkexpr.py": [
381367
945,
382368
1893
383369
],
384-
"project:mypy-0.782/mypy/checkmember.py": [
385-
388,
386-
475
387-
],
388370
"project:mypy-0.782/mypy/checkstrformat.py": [
389371
86,
390372
807,
391373
835,
392374
875
393375
],
394376
"project:mypy-0.782/mypy/errors.py": [
395-
291,
396-
294
377+
291
397378
],
398379
"project:mypy-0.782/mypy/find_sources.py": [
399380
107
@@ -411,9 +392,6 @@
411392
"project:mypy-0.782/mypy/nodes.py": [
412393
893
413394
],
414-
"project:mypy-0.782/mypy/scope.py": [
415-
113
416-
],
417395
"project:mypy-0.782/mypy/semanal.py": [
418396
729
419397
],
@@ -456,17 +434,11 @@
456434
"project:mypy-0.782/mypyc/codegen/emitmodule.py": [
457435
113
458436
],
459-
"project:mypy-0.782/mypyc/irbuild/builder.py": [
460-
746
461-
],
462437
"project:mypy-0.782/mypyc/irbuild/expression.py": [
463-
154,
464-
219,
465438
310,
466439
349
467440
],
468441
"project:mypy-0.782/mypyc/irbuild/ll_builder.py": [
469-
378,
470442
589
471443
],
472444
"project:mypy-0.782/mypyc/irbuild/statement.py": [
@@ -566,9 +538,6 @@
566538
84,
567539
190
568540
],
569-
"project:numpy-1.16.4/numpy/lib/arraypad.py": [
570-
1214
571-
],
572541
"project:numpy-1.16.4/numpy/lib/histograms.py": [
573542
1021
574543
],
@@ -595,9 +564,6 @@
595564
185,
596565
192
597566
],
598-
"project:numpy-1.16.4/tools/cythonize.py": [
599-
197
600-
],
601567
"project:numpy-1.16.4/tools/npy_tempita/__init__.py": [
602568
131,
603569
241,
@@ -607,34 +573,10 @@
607573
"project:pecos/test/pecos/apps/text2text/test_text2text.py": [
608574
139
609575
],
610-
"project:tensorflow/python/data/experimental/kernel_tests/optimization/filter_fusion_test.py": [
611-
54
612-
],
613-
"project:tensorflow/python/data/experimental/kernel_tests/optimization/map_and_filter_fusion_test.py": [
614-
69,
615-
109
616-
],
617-
"project:tensorflow/python/data/experimental/kernel_tests/optimization/map_parallelization_test.py": [
618-
50
619-
],
620-
"project:tensorflow/python/framework/convert_to_constants.py": [
621-
192,
622-
543
623-
],
624576
"project:tensorflow/python/framework/dtypes.py": [
625577
167,
626578
167
627579
],
628-
"project:tensorflow/python/keras/layers/core.py": [
629-
1001,
630-
1047,
631-
1392
632-
],
633-
"project:tensorflow/python/keras/layers/legacy_rnn/rnn_cell_wrapper_impl.py": [
634-
302,
635-
386,
636-
484
637-
],
638580
"project:tensorflow/python/kernel_tests/conv_ops_test.py": [
639581
2980,
640582
2987,
@@ -708,29 +650,10 @@
708650
"project:tensorflow/python/ops/signal/dct_ops.py": [
709651
101
710652
],
711-
"project:tensorflow/python/profiler/pprof_profiler.py": [
712-
135
713-
],
714-
"project:tensorflow/python/saved_model/function_deserialization.py": [
715-
235,
716-
355
717-
],
718-
"project:tensorflow/python/saved_model/load_v1_in_v2_test.py": [
719-
296,
720-
321,
721-
354
722-
],
723-
"project:tensorflow/python/saved_model/signature_serialization.py": [
724-
42
725-
],
726-
"project:tensorflow/python/tools/saved_model_cli_test.py": [
727-
250
728-
],
729653
"project:tornado-2.3/demos/appengine/markdown.py": [
730654
577,
731655
585,
732-
1504,
733-
1541
656+
1504
734657
],
735658
"project:tornado-2.3/demos/blog/blog.py": [
736659
112,
@@ -739,8 +662,7 @@
739662
"project:tornado-2.3/demos/blog/markdown.py": [
740663
577,
741664
585,
742-
1504,
743-
1541
665+
1504
744666
],
745667
"project:tornado-2.3/demos/s3server/s3server.py": [
746668
111
@@ -899,7 +821,6 @@
899821
],
900822
"project:twisted-12.1.0/twisted/manhole/explorer.py": [
901823
71,
902-
326,
903824
525
904825
],
905826
"project:twisted-12.1.0/twisted/manhole/gladereactor.py": [
@@ -1001,9 +922,6 @@
1001922
820,
1002923
837
1003924
],
1004-
"project:twisted-12.1.0/twisted/python/threadpool.py": [
1005-
163
1006-
],
1007925
"project:twisted-12.1.0/twisted/python/versions.py": [
1008926
212
1009927
],
@@ -1017,9 +935,6 @@
1017935
179,
1018936
271
1019937
],
1020-
"project:twisted-12.1.0/twisted/spread/jelly.py": [
1021-
884
1022-
],
1023938
"project:twisted-12.1.0/twisted/spread/pb.py": [
1024939
888
1025940
],
@@ -1081,9 +996,6 @@
1081996
52,
1082997
66
1083998
],
1084-
"project:twisted-12.1.0/twisted/web/soap.py": [
1085-
63
1086-
],
1087999
"project:twisted-12.1.0/twisted/web/static.py": [
10881000
147
10891001
],
@@ -1126,9 +1038,6 @@
11261038
833,
11271039
853
11281040
],
1129-
"project:twisted-12.1.0/twisted/web/xmlrpc.py": [
1130-
160
1131-
],
11321041
"project:twisted-12.1.0/twisted/words/protocols/jabber/error.py": [
11331042
174,
11341043
309

python-checks/src/main/java/org/sonar/python/checks/BuiltinShadowingAssignmentCheck.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class BuiltinShadowingAssignmentCheck extends PythonSubscriptionCheck {
5858
public static final String RENAME_PREFIX = "_";
5959
public static final String QUICK_FIX_MESSAGE_FORMAT = "Rename to " + RENAME_PREFIX+ " %s";
6060
private final Map<Symbol, PreciseIssue> variableIssuesRaised = new HashMap<>();
61-
public static final String ELLIPSIS = "ellipsis";
61+
private static final Set<String> notBuiltins = Set.of("ellipsis", "function");
6262

6363
@Override
6464
public void initialize(Context context) {
@@ -185,8 +185,7 @@ private boolean shouldReportIssue(Tree tree) {
185185
}
186186

187187
private boolean isBuiltInName(Name name) {
188-
// Workaround to fix the FP raised. A definite fix should be implemented as part of SONARPY-1531.
189-
if (ELLIPSIS.equals(name.name())) {
188+
if (notBuiltins.contains(name.name())) {
190189
return false;
191190
}
192191
return TypeShed.builtinSymbols().containsKey(name.name());

python-checks/src/test/resources/checks/builtinShadowing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ def ellipsis_test():
3838
ellipsis = "" # OK
3939
Ellipsis = 42 # Noncompliant {{Rename this variable; it shadows a builtin.}}
4040
ellipsis = "..." # OK
41+
42+
def function_test():
43+
function = "" # OK

0 commit comments

Comments
 (0)