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)
11
  • how did you get LOGGER? Commented Jan 14, 2020 at 11:44
  • please provide the exact error which you are getting Commented Jan 14, 2020 at 11:52
  • @AndreyBerenda LOGGER = logging.getLogger(name) Commented Jan 14, 2020 at 12:04
  • 1
    I suspect pylint is getting confused by the string concatenation. Commented Jan 14, 2020 at 12:23
  • 3
    I hate using it (it's a bad feature that causes far more bugs than it's worth), but if you remove the + operators and rely on implicit string literal concatenation, pylint might be happy. (Also you forgot a space at the end of one of your literals.) Commented Jan 14, 2020 at 12:26

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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.)
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.