wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Improve WPS323 diagnostics

Open strmwalker opened this issue 4 years ago • 2 comments

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 extra keyword 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.

strmwalker avatar Feb 16 '21 13:02 strmwalker

+1 bump

FyZzyss avatar Aug 01 '22 09:08 FyZzyss

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.

cyyc1 avatar Oct 01 '22 09:10 cyyc1