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

Detect missing arguments in logging format strings #9999

Open
sam-s opened this issue Oct 2, 2024 · 1 comment · May be fixed by #10108 or #10128
Open

Detect missing arguments in logging format strings #9999

sam-s opened this issue Oct 2, 2024 · 1 comment · May be fixed by #10108 or #10128
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@sam-s
Copy link

sam-s commented Oct 2, 2024

Current problem

The following error should be easily detectable:

import logging
logging.info("foo %s")  # missing format arg

the missing arguments should be easily detectable, like we already get too-many-format-args on

logging.warning("foo",1,2,3) # extra format args

Desired solution

I want pylint to issue the too-few-format-args error on the above code.

Additional context

No response

@sam-s sam-s added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 2, 2024
@zenlyj
Copy link
Contributor

zenlyj commented Nov 6, 2024

thanks for the report, you may be referring to logging-too-many-args and logging-too-few-args here.

seems that the checker is skipping these checks if no arguments are provided:

if not num_args:
# If no args were supplied the string is not interpolated and can contain
# formatting characters - it's used verbatim. Don't check any further.
return

i agree that we should probably raise logging-too-few-args when the logging message contains placeholders but no arguments are provided. such cases are more likely to be oversights rather than intentional verbatim messages.

@zenlyj zenlyj added False Negative 🦋 No message is emitted but something is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 6, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation Help wanted 🙏 Outside help would be appreciated, good for new contributors labels Nov 6, 2024
andydrewwm added a commit to andydrewwm/pylint that referenced this issue Dec 10, 2024
Implements the detection of too-few-args in logging format strings.
Includes new test cases and documentation updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants