The output from pylint states:
nltk/nltk/tag/perceptron.py:203: [W1202(logging-format-interpolation), PerceptronTagger.train] Use % formatting in logging functions and pass the % parameters as arguments
But looking at the code https://github.com/nltk/nltk/blob/develop/nltk/tag/perceptron.py#L203, there isn't any usage of %
string formatting:
logging.info("Iter {0}: {1}/{2}={3}".format(iter_, c, n, _pc(c, n)))
Am I missing something or misinterpreting the W1202 message?
How should the code line be change such that the W1202 goes away when pylinting?
Message Interpretation:
It's saying that you should pass the parameters as arguments and pretend that you were using the (old) %
formatting style (but pass them in as args instead of using %
and wrapping the args in parens). It is not saying that you're using %
for string formatting in the log message.
Why is it like this:
The reason you'd want to pass this way is so that the string only goes through templated substitution if the message is actually created by some log handler. String operations are always expensive from a performance standpoint. If you're doing a ton of logging at the DEBUG level, but rarely use level DEBUG in your application, for instance, this can add up fast.
How to fix it:
I think if it were changed to logging.info("Iter %d: %d/%d=%d", iter_, c, n, _pc(c, n)))
the message would go away (assuming they are digits, hard to tell from the example).