wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Improve WPS323 diagnostics
What's wrong
Right now this code triggers WPS323 violation (documentation):
import logging
logging.info('Hello, %s !', 'World')
Running flake8 on this code gives this:
flake8 wps323_demo.py
wps323_demo.py:1:1: D100 Missing docstring in public module
wps323_demo.py:3:14: WPS323 Found `%` string formatting
Python documentation suggests using % for log formatting (link). People following documentation usually get confused, and just disable the rule.
How it should be
I treat linter as compiler for python. Compiler's job is not to take correct code and produce machine code, but take incorrect and provide useful diagnostics.
There are several options:
- allow
%formatting specifically in logging calls - add suggestion to use
extrakeyword argument for formatting
I am not aware if the first option is possible to detect. I am willing to make a PR solving this issue.
I have seen #1304 and related commit, just think we can do better.
+1 bump
Another case where we explicitly need "%" is when we use strftime() and strptime() format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
I think WPS should be more lenient for these two cases.