Method: pylint.checkers.utils.parse_format_string
Calls: 116, Exceptions: 4, Paths: 10Back
Path 1: 77 calls (0.66)
'%s' (24) '%d' (7) 'String %s' (6) '%s, %s' (4) '%s%s%s' (4) '%d %s' (3) 'String %f' (3) 'String %s %s' (3) 'msg: %s' (3) '%s %s' (3)
tuple (77)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 2: 23 calls (0.2)
'%(Param_1)s %(Param_2)s' (9) '%(PARG_1)d %(PARG_2)d' (5) '%(key)d' (4) '%(key)s' (3) '%(key)f' (1) '%(key)x' (1)
tuple (23)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 3: 9 calls (0.08)
'String' (4) '{}' (1) '{0}' (1) '{named}' (1) '{} {named}' (1) '{0} {named}' (1)
tuple (9)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 4: 1 calls (0.01)
'%s measures %.2f' (1)
tuple (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 5: 1 calls (0.01)
'%(PARG_1)d %d' (1)
tuple (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 6: 1 calls (0.01)
'%2z' (1)
UnsupportedFormatCharacter (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 7: 1 calls (0.01)
'strange format %2' (1)
IncompleteFormatString (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 8: 1 calls (0.01)
'' (1)
tuple (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 9: 1 calls (0.01)
'%s%' (1)
IncompleteFormatString (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types
Path 10: 1 calls (0.01)
'%s%y' (1)
UnsupportedFormatCharacter (1)
1def parse_format_string(
2 format_string: str,
3) -> tuple[set[str], int, dict[str, str], list[str]]:
4 """Parses a format string, returning a tuple (keys, num_args).
5
6 Where 'keys' is the set of mapping keys in the format string, and 'num_args' is the number
7 of arguments required by the format string. Raises IncompleteFormatString or
8 UnsupportedFormatCharacter if a parse error occurs.
9 """
10 keys = set()
11 key_types = {}
12 pos_types = []
13 num_args = 0
14
15 def next_char(i: int) -> tuple[int, str]:
16 i += 1
17 if i == len(format_string):
18 raise IncompleteFormatString
19 return (i, format_string[i])
20
21 i = 0
22 while i < len(format_string):
23 char = format_string[i]
24 if char == "%":
25 i, char = next_char(i)
26 # Parse the mapping key (optional).
27 key = None
28 if char == "(":
29 depth = 1
30 i, char = next_char(i)
31 key_start = i
32 while depth != 0:
33 if char == "(":
34 depth += 1
35 elif char == ")":
36 depth -= 1
37 i, char = next_char(i)
38 key_end = i - 1
39 key = format_string[key_start:key_end]
40
41 # Parse the conversion flags (optional).
42 while char in "#0- +":
43 i, char = next_char(i)
44 # Parse the minimum field width (optional).
45 if char == "*":
46 num_args += 1
47 i, char = next_char(i)
48 else:
49 while char in string.digits:
50 i, char = next_char(i)
51 # Parse the precision (optional).
52 if char == ".":
53 i, char = next_char(i)
54 if char == "*":
55 num_args += 1
56 i, char = next_char(i)
57 else:
58 while char in string.digits:
59 i, char = next_char(i)
60 # Parse the length modifier (optional).
61 if char in "hlL":
62 i, char = next_char(i)
63 # Parse the conversion type (mandatory).
64 flags = "diouxXeEfFgGcrs%a"
65 if char not in flags:
66 raise UnsupportedFormatCharacter(i)
67 if key:
68 keys.add(key)
69 key_types[key] = char
70 elif char != "%":
71 num_args += 1
72 pos_types.append(char)
73 i += 1
74 return keys, num_args, key_types, pos_types