Skip to content

Commit bdbcc1b

Browse files
committed
fixes after review
1 parent 1eda634 commit bdbcc1b

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

rules/S7508/python/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Redundant collection casts should be avoided",
2+
"title": "Redundant collection functions should be avoided",
33
"type": "CODE_SMELL",
44
"status": "ready",
55
"remediation": {

rules/S7508/python/rule.adoc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This rule raises an issue when the argument to or the return type from the functions `list()`, `tuple()`, `set()`, `sorted()`, or `reversed()` are unnecessarily casted.
1+
This rule raises an issue when the functions `list()`, `tuple()`, `set()`, `sorted()`, or `reversed()` are unnecessarily wrapped around each other's return values or used to convert values that don't require conversion.
22

33
== Why is this an issue?
44

@@ -7,9 +7,9 @@ Python's built-in functions for processing iterables such as `list()`, `tuple()`
77

88
== How to fix it
99

10-
When the outer function is given a collection but could be given an iterable, the unnecessary cast to the collection should be removed. For example, in `sorted(list(iterable))`, the outer `sorted()` function can accept an iterable directly, so the inner `list()` call is redundant and should be removed.
10+
When the outer function is given a collection but could have been given an iterable, the unnecessary conversion should be removed. For example, in `sorted(list(iterable))`, the outer `sorted()` function can accept an iterable directly, so the inner `list()` call is redundant and should be removed.
1111

12-
When the function `sorted()` is casted to `list()`, remove the cast, since `sorted()` already returns a list.
12+
When the function `sorted()` is wrapped with `list()`, remove this conversion operation, since `sorted()` already returns a list.
1313

1414
=== Code examples
1515

@@ -19,8 +19,6 @@ When the function `sorted()` is casted to `list()`, remove the cast, since `sort
1919
----
2020
iterable = (3, 1, 4, 1)
2121
22-
list_of_list = list(list(iterable)) # Noncompliant
23-
set_of_list = set(list(iterable)) # Noncompliant
2422
sorted_of_list = list(sorted(iterable)) # Noncompliant
2523
----
2624

@@ -30,16 +28,14 @@ sorted_of_list = list(sorted(iterable)) # Noncompliant
3028
----
3129
iterable = (3, 1, 4, 1)
3230
33-
list_of_list = list(iterable) # Noncompliant
34-
set_of_list = set(iterable) # Noncompliant
3531
sorted_of_list = sorted(iterable) # Noncompliant
3632
----
3733

3834
== Resources
3935
=== Documentation
40-
* Python Documentation - https://docs.python.org/3/library/functions.html#list[list]
41-
* Python Documentation - https://docs.python.org/3/library/functions.html#tuple[tuple]
42-
* Python Documentation - https://docs.python.org/3/library/functions.html#set[set]
36+
* Python Documentation - https://docs.python.org/3/library/stdtypes.html#list[list]
37+
* Python Documentation - https://docs.python.org/3/library/stdtypes.html#tuple[tuple]
38+
* Python Documentation - https://docs.python.org/3/library/stdtypes.html#set[set]
4339
* Python Documentation - https://docs.python.org/3/library/functions.html#sorted[sorted]
4440
* Python Documentation - https://docs.python.org/3/library/functions.html#reversed[reversed]
4541

0 commit comments

Comments
 (0)