Skip to content

Commit

Permalink
Change the logging-format-style to use name identifier instead of…
Browse files Browse the repository at this point in the history
… their corresponding Python identifiers

This is to prevent users having to think about escaping the default value for
``logging-format-style`` in the generated config file. Also our config parsing
utilities don't quite support escaped values when it comes to ``choices`` detection,
so this would have needed various hacks around that.

Close #2614
  • Loading branch information
PCManticore committed Nov 28, 2018
1 parent 484d172 commit 754ce1d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
25 changes: 25 additions & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,31 @@
Pylint's ChangeLog
------------------

What's New in Pylint 2.2.2?
=========================

Release date: 2018-11-28

* Change the ``logging-format-style`` to use name identifier instead of their
corresponding Python identifiers

This is to prevent users having to think about escaping the default value for
``logging-format-style`` in the generated config file. Also our config parsing
utilities don't quite support escaped values when it comes to ``choices`` detection,
so this would have needed various hacks around that.

Closes #2614


What's New in Pylint 2.2.1?
=========================

Release date: 2018-11-27

* Fix a crash caused by `implicit-str-concat-in-sequence` and multi-bytes characters.

Closes #2610

What's New in Pylint 2.2?
=========================

Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/2.2.rst
Expand Up @@ -20,6 +20,9 @@ New checkers
* ``logging-format-style`` is a new option for the logging checker for usage of
str.format() style format strings in calls to loggers.

It accepts two options: ``--logging-format-style=old`` for using `%` style formatting,
which is the assumed default, and ``--logging-format-style=new`` for using `{}` style formatting.

* ``implicit-str-concat-in-sequence`` detects string concatenation inside lists, sets & tuples.

Example of code that would generate such warning:
Expand Down
13 changes: 7 additions & 6 deletions pylint/checkers/logging.py
Expand Up @@ -139,11 +139,12 @@ class LoggingChecker(checkers.BaseChecker):
(
"logging-format-style",
{
"default": "%",
"default": "old",
"type": "choice",
"metavar": "<% or {>",
"choices": ["%", "{"],
"help": "Format style used to check logging format string",
"metavar": "<old (%) or new ({)>",
"choices": ["old", "new"],
"help": "Format style used to check logging format string. "
"`old` means using % formatting, while `new` is for `{}` formatting.",
},
),
)
Expand Down Expand Up @@ -295,15 +296,15 @@ def _check_format_string(self, node, format_arg):
required_num_args = 0
else:
try:
if self._format_style == "%":
if self._format_style == "old":
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 == "new":
keys, num_args, manual_pos_arg = utils.parse_format_method_string(
format_string
)
Expand Down
2 changes: 1 addition & 1 deletion pylint/test/unittest_checker_logging.py
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="new")
def test_brace_format_style(self):
stmts = astroid.extract_node(
"""
Expand Down

0 comments on commit 754ce1d

Please sign in to comment.