0

I have read all the other solutions for this error and modified my code accordingly, but the error still persists. What am I doing wrong here?

This is my code:

LOGGER.error(
    'There are no frames to download in the chosen ' +
    'time range: %s to %s. Try a different time range with the ' +
    '--start_date and --end_date options. This error can also arise ' +
    'if the downloaded files have been deleted or modified during' +
    'execution.', str(start_date), str(end_date))

Error message:

.tox/pylint/lib/python3.8/site-packages/polaris/fetch/data_fetch_decoder.py:143:8: W1201: Specify string format arguments as logging function parameters (logging-not-lazy)

------------------------------------------------------------------ Your code has been rated at 9.99/10 (previous run: 9.99/10, +0.00)

ERROR: InvocationError for command /home/jai/polaris/.tox/pylint/bin/pylint tests .tox/pylint/lib/python3.8/site-packages/polaris .tox/pylint/lib/python3.8/site-packages/contrib (exited with code 4)

Update 1: Removing the str() conversion gives me the same output but the error persists. As a comment pointed out, the error is caused by some other issue, but my question is still about why is linter giving me that output.

Update 2: Used implicit string concatenation and now I get the following error

W1202: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)

Code for implicit string concatenation using formatting:

LOGGER.error(
            '{0} {1} {2} {3} {4}'.format(
                'There are no frames to download in the chosen time range:',
                '%s to %s. Try a different time range with the',
                '--start_date and --end_date options. This error can',
                'also arise if the downloaded files have been deleted',
                'or modified during execution.'), start_date, end_date)
Jai Kotia
  • 166
  • 2
  • 16

2 Answers2

1

This fixed the linter warning and my error:

LOGGER.error(
            ' '.join([
                'There are no frames to download in the chosen time ',
                'range: %s to %s. Try a different time range with ',
                'the --start_date and --end_date options. This error ',
                'can also arise if the downloaded files have been',
                'deleted or modified during execution.'
            ]), start_date, end_date)

As @user2357112supportsMonica pointed out, pylint is getting confused by using + for concatenation, so I used implicit string literal concatenation. Voila, it works now!

Jai Kotia
  • 166
  • 2
  • 16
  • 2
    I meant like `'a' 'b' 'c'`, not `''.join(['a', 'b', 'c'])`, but if this gets pylint to shut up, I guess that works too. (It inhibits compile-time constant folding and has the opposite of the performance effect the poorly-implemented linter check was intended to promote, though.) – user2357112 Jan 14 '20 at 19:20
0

W: 70,12: Specify string format arguments as logging function parameters (logging-not-lazy) LOGGER.info("Information: %s"% result)

--CHANGE TO--

LOGGER.info(" Information: %s", result)

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
satyanarayana
  • 367
  • 2
  • 4