Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option: logging-format-style for logging checker #2521

Merged
merged 10 commits into from Oct 4, 2018

Conversation

Projects
None yet
3 participants
@pinealan
Copy link
Contributor

commented Sep 27, 2018

Steps

  • Add myself to contributors
  • Add to changelog
  • Add to docs/whatsnew/2.2.rst

Description
logging-format-style accepts one of '%' or '{', (defaults to '%'). When '{' is selected, logging checker assumes str.format() style format strings for calls to the logging.

This PR came about when pylint threw E1205 logging-too-many-args at my project that uses '{' style format strings. This was because pylint was unable to count the required number of args for the format string. The new feature indirectly fixes that by allowing the proper interpretation of that format string. The possibility for others to implement the '$' style template strings parsing is also open.

@pinealan pinealan force-pushed the pinealan:master branch from c2d5f9b to 080cad6 Sep 27, 2018

@coveralls

This comment has been minimized.

Copy link

commented Sep 27, 2018

Coverage Status

Coverage increased (+0.3%) to 89.904% when pulling 6676f54 on pinealan:master into 540e26d on PyCQA:master.

@pinealan pinealan changed the title Add logging-format-style to logging checker New option: logging-format-style for logging checker Sep 27, 2018

@PCManticore
Copy link
Member

left a comment

Thanks for the PR @pinealan ! The code and the feature look good, but I'd suggest reusing parse_format_method_string from checkers/strings.py instead of adding a new function. Maybe we can also move that to utils.

@@ -535,6 +535,67 @@ def next_char(i):
return keys, num_args, key_types, pos_types


def parse_brace_format_string(format_string: str) -> Tuple[Set[str], int]:

This comment has been minimized.

Copy link
@PCManticore

PCManticore Oct 2, 2018

Member

It's not totally obvious but we have parse_format_method_string in checkers/strings.py, which does the same thing. It's used by the string checkers for warning about passing invalid format keys when formatting with .format().

This comment has been minimized.

Copy link
@pinealan

pinealan Oct 3, 2018

Author Contributor

Thanks for pointing that out. I will refactor accordingly.

pinealan added some commits Oct 3, 2018

@@ -535,6 +536,104 @@ def next_char(i):
return keys, num_args, key_types, pos_types


if PY3K:

This comment has been minimized.

Copy link
@PCManticore

PCManticore Oct 3, 2018

Member

Since we're now running only on Python 3, feel free to remove the else clause of this check.

This comment has been minimized.

Copy link
@pinealan

pinealan Oct 3, 2018

Author Contributor

Oh cool got it.

pinealan added some commits Oct 3, 2018

@PCManticore PCManticore merged commit 0dd573f into PyCQA:master Oct 4, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@PCManticore

This comment has been minimized.

Copy link
Member

commented Oct 4, 2018

Thanks a lot @pinealan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.