Skip to content

Commit

Permalink
Fix black and mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pinealan committed Sep 27, 2018
1 parent 0ec310d commit 080cad6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pylint/checkers/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class LoggingChecker(checkers.BaseChecker):
"default": "%",
"type": "choice",
"metavar": "<% or {>",
"choices": ['%', '{'],
"choices": ["%", "{"],
"help": "Format style used to check logging format string",
},
),
Expand Down Expand Up @@ -295,15 +295,15 @@ def _check_format_string(self, node, format_arg):
required_num_args = 0
else:
try:
if self._format_style == '%':
if self._format_style == "%":
keyword_args, required_num_args, _, _ = utils.parse_format_string(
format_string
)
if keyword_args:
# Keyword checking on logging strings is complicated by
# special keywords - out of scope.
return
elif self._format_style == '{':
elif self._format_style == "{":
_, required_num_args = utils.parse_brace_format_string(
format_string
)
Expand Down
34 changes: 17 additions & 17 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,47 +539,47 @@ def parse_brace_format_string(format_string: str) -> Tuple[Set[str], int]:
"""Parses a str.format() style format string, otherwise the same as
parse_format_string().
"""
keys = set()
keys = set() # type: Set[str]
num_args = 0

def next_char(i):
if i+1 > len(format_string):
print('Final: ', format_string[:i])
if i + 1 > len(format_string):
print("Final: ", format_string[:i])
raise IncompleteFormatString
return i+1, format_string[i]
return i + 1, format_string[i]

i = 0
while i < len(format_string):
i, char = next_char(i)
if char == '{':
if char == "{":
i, char = next_char(i)
key = ''
key = ""
# Parse escaped brace character
if char == '{':
if char == "{":
continue
# Parse field_name (optional)
while char not in '!:}':
if char in '[.':
while char not in '!:}':
while char not in "!:}":
if char in "[.":
while char not in "!:}":
i, char = next_char(i)
break
key += char
i, char = next_char(i)
# Parse conversion (optional)
if char == '!':
if char == "!":
i, char = next_char(i)
if char in 'rsa':
if char in "rsa":
i, char = next_char(i)
else:
raise UnsupportedFormatCharacter
# Parse format_spec (optional)
if char == ':':
if char == ":":
i, char = next_char(i)
# ignore the format_spec details
while char != '}':
while char != "}":
i, char = next_char(i)
# Parse end of replacement field
if char == '}':
if char == "}":
if key:
if key not in keys:
num_args += 1
Expand All @@ -588,9 +588,9 @@ def next_char(i):
num_args += 1
continue
raise UnsupportedFormatCharacter
if char == '}':
if char == "}":
i, char = next_char(i)
if char == '}':
if char == "}":
continue
raise UnsupportedFormatCharacter
return keys, num_args
Expand Down
2 changes: 1 addition & 1 deletion pylint/test/unittest_checker_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_nonstandard_logging_module(self):
with self.assertAddsMessages(Message("logging-not-lazy", node=stmts[1])):
self.checker.visit_call(stmts[1])

@set_config(logging_format_style='{')
@set_config(logging_format_style="{")
def test_brace_format_string(self):
stmts = astroid.extract_node(
"""
Expand Down
28 changes: 14 additions & 14 deletions pylint/test/unittest_checkers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ class OneClass: #@

def test_parse_brace_format_string():
samples = [
('{}', 1),
('{}:{}', 2),
('{field}', 1),
('{:5}', 1),
('{:10}', 1),
('{field:10}', 1),
('{field:10}{{}}', 1),
('{:5}{!r:10}', 2),
('{:5}{}{{}}{}', 3),
('{0}{1}{0}', 2),
('Coordinates: {latitude}, {longitude}', 2),
('X: {0[0]}; Y: {0[1]}', 1),
('{:*^30}', 1),
('{!r:}', 1),
("{}", 1),
("{}:{}", 2),
("{field}", 1),
("{:5}", 1),
("{:10}", 1),
("{field:10}", 1),
("{field:10}{{}}", 1),
("{:5}{!r:10}", 2),
("{:5}{}{{}}{}", 3),
("{0}{1}{0}", 2),
("Coordinates: {latitude}, {longitude}", 2),
("X: {0[0]}; Y: {0[1]}", 1),
("{:*^30}", 1),
("{!r:}", 1),
]
for fmt, count in samples:
keys, num = utils.parse_brace_format_string(fmt)
Expand Down

0 comments on commit 080cad6

Please sign in to comment.