Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint should not emit logging-not-lazy when using explicit string concatenation for the message #8410

Closed
yilei opened this issue Mar 8, 2023 · 2 comments · Fixed by #8546 or #9093
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@yilei
Copy link
Contributor

yilei commented Mar 8, 2023

Bug description

# pylint: disable=missing-docstring
import logging

logging.error('first' + 'second')

Since there is no difference in byte code whether the string is explicitly concatenated with + or not, the logging isn't really not lazy.

Extra context: the Black formatter will by default wrap long strings in parens with extra indentation:

logging.info("this is a super super super super super super super super super super super super super long message: %s", content)

is reformatted to:

logging.info(
    (
        "this is a super super super super super super super super super super super"
        " super super long message: %s"
    ),
    content,
)

Not all people like the extra indentation level, so they could workaround this by using explicit str concatenations:

logging.info(
    "this is a super super super super super super super super super super"
    + " super super super long message: %s",
    content
)

Above code won't be wrapped. See example: https://black.vercel.app/?version=stable&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AGJAJZdAD2IimZxl1N_Wl9XMO7It8_a9_zDM7vdFRRO_5rVL_TbaRMZFsldltUpcVRrU3ciQwYZYh1fEUKKhGKajA7blNBzUd1tD9xf20knxX9nUEnMw4r5um_wmnJAbkpayNa6vKQJW31lZlMZ-h8FDJRG0yvSqO-tn_wDhAqHt1M950Ia2LlS8KBt25Oi9a35Qd-DQeQ5aXTpAAAAAJCojbjuFauOAAGyAYoDAAAVp5UpscRn-wIAAAAABFla

But this triggers the logging-not-lazy error where it really shouldn't.

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module flag3app
a.py:4:0: W1201: Use lazy % formatting in logging functions (logging-not-lazy)

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

Expected behavior

It should not raise logging-not-lazy

Pylint version

pylint 2.17.0
astroid 2.15.0
Python 3.11.2 (main, Mar  3 2023, 16:02:46) [GCC 12.2.0]

OS / Environment

No response

Additional dependencies

No response

@yilei yilei added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 8, 2023
@yilei
Copy link
Contributor Author

yilei commented Mar 20, 2023

Maintainer opinions before I send a PR?

@DanielNoord
Copy link
Collaborator

Please go ahead! Seems like a good change!

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants