Skip to content

Commit f82f995

Browse files
committed
Catch .format() use in log string interpoliation check
This adds checking for using .format() instead of % when looking for cases of preformatting log strings. Change-Id: Ia12f898ca3d206c9da0e5057c7223e124ee2548c Signed-off-by: Sean McGinnis <[email protected]>
1 parent 31e9c87 commit f82f995

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

hacking/checks/other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ def hacking_delayed_string_interpolation(logical_line, noqa):
5555
# There are some cases where string formatting of the arguments are
5656
# needed, so don't include those when checking.
5757
line = re.sub(r",.*", '', line)
58-
if '%' in line:
58+
if '%' in line or '.format' in line:
5959
yield 0, msg

hacking/tests/checks/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class OthersTestCase(tests.TestCase):
2525
@ddt.data(
2626
(1, 'LOG.debug("Test %s" % foo)', None),
2727
(0, 'LOG.info("Test %s", foo)', None),
28+
(1, 'LOG.info("Test {}".format(foo))', None),
2829
(0, 'LOG.error("Test %s" % foo)', '# noqa'),
2930
(1, 'LOG.debug("Test %s" % "foo")', None),
3031
(0, 'LOG.debug("Test %s", "foo")', None),

0 commit comments

Comments
 (0)