diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | pylint/checkers/logging.py | 7 | ||||
-rw-r--r-- | pylint/test/unittest_checker_logging.py | 7 |
3 files changed, 18 insertions, 1 deletions
@@ -2,6 +2,7 @@ Pylint's ChangeLog ------------------ +<<<<<<< HEAD What's New in Pylint 1.8.3? ========================== @@ -17,6 +18,10 @@ Release date: - `__doc__` can be used to specify a docstring for a module without passing it as a first-statement string. + * Don't crash on invalid strings when checking for `logging-format-interpolation` + + Close #1944 + * Fix false positive ``inconsistent-return-statements`` message by avoiding useless exception inference if the exception is not handled. diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index 051fa7589..f87242fb2 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -263,7 +263,12 @@ def is_complex_format_str(node): inferred = utils.safe_infer(node) if inferred is None or not isinstance(inferred.value, six.string_types): return True - for _, _, format_spec, _ in string.Formatter().parse(inferred.value): + try: + parsed = list(string.Formatter().parse(inferred.value)) + except ValueError: + # This format string is invalid + return False + for _, _, format_spec, _ in parsed: if format_spec: return True return False diff --git a/pylint/test/unittest_checker_logging.py b/pylint/test/unittest_checker_logging.py index 6075a2a2e..a87c3f542 100644 --- a/pylint/test/unittest_checker_logging.py +++ b/pylint/test/unittest_checker_logging.py @@ -27,6 +27,13 @@ class TestLoggingModuleDetection(CheckerTestCase): with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])): self.checker.visit_call(stmts[1]) + def test_dont_crash_on_invalid_format_string(self): + node = astroid.parse(''' + import logging + logging.error('0} - {1}'.format(1, 2)) + ''') + self.walk(node) + def test_detects_renamed_standard_logging_module(self): stmts = astroid.extract_node(""" import logging as blogging #@ |