pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Floating point logging format gives false error

Open ebbek opened this issue 2 years ago • 2 comments

Bug description

Pylint issues the error logging-too-many-args for the following file (named logerr.py:

#! /usr/bin/env python3
"""
Demonstrate wrong message from pylint
"""
import logging
logging.warning( "The frequency is: %f MHz", 2.3 )

Configuration

[LOGGING]
logging-format-style=new

Command used

pylint logerr.py

Pylint output

************* Module logerr
logerr.py:8:0: E1205: Too many arguments for logging format string (logging-too-many-args)

Expected behavior

No errors.

Pylint version

pylint 3.0.0
astroid 3.0.0
Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]

OS / Environment

Windows 11

ebbek avatar Oct 05 '23 13:10 ebbek

Is this a Windows thing? I'm not getting any errors on Ubuntu.

nickdrozd avatar Oct 05 '23 16:10 nickdrozd

To reproduce you also need:

[LOGGING]
logging-format-style=new

The new style is about {} style formatting and the old style %f so pylint is confused about the old style being used when the new style is declared.

It seems

logging.warning( "The frequency is: {:.2f} MHz", 2.3 )

also raises a false positive with

[LOGGING]
logging-format-style=old

Opened #9121

Pierre-Sassoulas avatar Oct 05 '23 20:10 Pierre-Sassoulas