Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@
print("S\x1cP\x1dL\x1eI\x1fT".split())
print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))

# leading/trailing whitespace should not count towards maxsplit
" a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,28 @@ fn split_default(
let string_val = str_value.to_str();
match max_split.cmp(&0) {
Ordering::Greater => {
// Autofix for `maxsplit` without separator not yet implemented, as
// `split_whitespace().remainder()` is not stable:
// https://doc.rust-lang.org/std/str/struct.SplitWhitespace.html#method.remainder
None
let Ok(max_split) = usize::try_from(max_split) else {
return None;
};
let list_items: Vec<&str> = if direction == Direction::Left {
string_val
.trim_start_matches(py_unicode_is_whitespace)
.splitn(max_split + 1, py_unicode_is_whitespace)
.filter(|s| !s.is_empty())
.collect()
} else {
let mut items: Vec<&str> = string_val
.trim_end_matches(py_unicode_is_whitespace)
.rsplitn(max_split + 1, py_unicode_is_whitespace)
.filter(|s| !s.is_empty())
.collect();
items.reverse();
items
};
Some(construct_replacement(
&list_items,
str_value.first_literal_flags(),
))
}
Ordering::Equal => {
// Behavior for maxsplit = 0 when sep is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ help: Replace with list literal
16 16 | "a,b,c,d".split(sep=",")
17 17 | "a,b,c,d".split(sep=None)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:15:1
|
13 | "a,b,c,d".split(None)
Expand All @@ -107,6 +107,16 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

ℹ Safe fix
12 12 | "a,b,c,d".split(",")
13 13 | "a,b,c,d".split(None)
14 14 | "a,b,c,d".split(",", 1)
15 |-"a,b,c,d".split(None, 1)
15 |+["a,b,c,d"]
16 16 | "a,b,c,d".split(sep=",")
17 17 | "a,b,c,d".split(sep=None)
18 18 | "a,b,c,d".split(sep=",", maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:16:1
|
Expand Down Expand Up @@ -173,7 +183,7 @@ help: Replace with list literal
20 20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 21 | "a,b,c,d".split(maxsplit=1, sep=None)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:19:1
|
17 | "a,b,c,d".split(sep=None)
Expand All @@ -185,6 +195,16 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

ℹ Safe fix
16 16 | "a,b,c,d".split(sep=",")
17 17 | "a,b,c,d".split(sep=None)
18 18 | "a,b,c,d".split(sep=",", maxsplit=1)
19 |-"a,b,c,d".split(sep=None, maxsplit=1)
19 |+["a,b,c,d"]
20 20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 22 | "a,b,c,d".split(",", maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:20:1
|
Expand All @@ -207,7 +227,7 @@ help: Replace with list literal
22 22 | "a,b,c,d".split(",", maxsplit=1)
23 23 | "a,b,c,d".split(None, maxsplit=1)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:21:1
|
19 | "a,b,c,d".split(sep=None, maxsplit=1)
Expand All @@ -219,6 +239,16 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

ℹ Safe fix
18 18 | "a,b,c,d".split(sep=",", maxsplit=1)
19 19 | "a,b,c,d".split(sep=None, maxsplit=1)
20 20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 |-"a,b,c,d".split(maxsplit=1, sep=None)
21 |+["a,b,c,d"]
22 22 | "a,b,c,d".split(",", maxsplit=1)
23 23 | "a,b,c,d".split(None, maxsplit=1)
24 24 | "a,b,c,d".split(maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:22:1
|
Expand All @@ -241,7 +271,7 @@ help: Replace with list literal
24 24 | "a,b,c,d".split(maxsplit=1)
25 25 | "a,b,c,d".split(maxsplit=1.0)

SIM905 Consider using a list literal instead of `str.split`
SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:23:1
|
21 | "a,b,c,d".split(maxsplit=1, sep=None)
Expand All @@ -253,7 +283,17 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

SIM905 Consider using a list literal instead of `str.split`
ℹ Safe fix
20 20 | "a,b,c,d".split(maxsplit=1, sep=",")
21 21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 22 | "a,b,c,d".split(",", maxsplit=1)
23 |-"a,b,c,d".split(None, maxsplit=1)
23 |+["a,b,c,d"]
24 24 | "a,b,c,d".split(maxsplit=1)
25 25 | "a,b,c,d".split(maxsplit=1.0)
26 26 | "a,b,c,d".split(maxsplit=1)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:24:1
|
22 | "a,b,c,d".split(",", maxsplit=1)
Expand All @@ -265,7 +305,17 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

SIM905 Consider using a list literal instead of `str.split`
ℹ Safe fix
21 21 | "a,b,c,d".split(maxsplit=1, sep=None)
22 22 | "a,b,c,d".split(",", maxsplit=1)
23 23 | "a,b,c,d".split(None, maxsplit=1)
24 |-"a,b,c,d".split(maxsplit=1)
24 |+["a,b,c,d"]
25 25 | "a,b,c,d".split(maxsplit=1.0)
26 26 | "a,b,c,d".split(maxsplit=1)
27 27 | "a,b,c,d".split(maxsplit=0)

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:26:1
|
24 | "a,b,c,d".split(maxsplit=1)
Expand All @@ -277,6 +327,16 @@ SIM905 Consider using a list literal instead of `str.split`
|
help: Replace with list literal

ℹ Safe fix
23 23 | "a,b,c,d".split(None, maxsplit=1)
24 24 | "a,b,c,d".split(maxsplit=1)
25 25 | "a,b,c,d".split(maxsplit=1.0)
26 |-"a,b,c,d".split(maxsplit=1)
26 |+["a,b,c,d"]
27 27 | "a,b,c,d".split(maxsplit=0)
28 28 | "VERB AUX PRON ADP DET".split(" ")
29 29 | ' 1 2 3 '.split()

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:27:1
|
Expand Down Expand Up @@ -1439,6 +1499,7 @@ help: Replace with list literal
166 |+print(["S", "P", "L", "I", "T"])
167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
169 169 |

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:167:7
Expand All @@ -1458,6 +1519,8 @@ help: Replace with list literal
167 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
167 |+print([">"])
168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
169 169 |
170 170 | # leading/trailing whitespace should not count towards maxsplit

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:168:7
Expand All @@ -1466,6 +1529,8 @@ SIM905 [*] Consider using a list literal instead of `str.split`
167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169 |
170 | # leading/trailing whitespace should not count towards maxsplit
|
help: Replace with list literal

Expand All @@ -1475,3 +1540,41 @@ help: Replace with list literal
167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0))
168 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
168 |+print(["<"])
169 169 |
170 170 | # leading/trailing whitespace should not count towards maxsplit
171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:171:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
|
help: Replace with list literal

ℹ Safe fix
168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0))
169 169 |
170 170 | # leading/trailing whitespace should not count towards maxsplit
171 |-" a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
171 |+["a", "b", "c d "] # ["a", "b", "c d "]
172 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]

SIM905 [*] Consider using a list literal instead of `str.split`
--> SIM905.py:172:1
|
170 | # leading/trailing whitespace should not count towards maxsplit
171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: Replace with list literal

ℹ Safe fix
169 169 |
170 170 | # leading/trailing whitespace should not count towards maxsplit
171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "]
172 |-" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"]
172 |+[" a b", "c", "d"] # [" a b", "c", "d"]