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 #10108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexprabhat99
Copy link

@alexprabhat99 alexprabhat99 commented Dec 3, 2024

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

This PR raises logging-too-few-args when the logging message contains placeholders but no arguments are provided as suggested by @zenlyj here: #9999 (comment)

Closes #9999

Copy link
Contributor

github-actions bot commented Dec 4, 2024

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on home-assistant:
The following messages are now emitted:

  1. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/4deaeaeda048112c9ebd5e3883bccfcadb8dded6/homeassistant/components/homeworks/config_flow.py#L175
  2. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/4deaeaeda048112c9ebd5e3883bccfcadb8dded6/homeassistant/components/sisyphus/light.py#L88
  3. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/4deaeaeda048112c9ebd5e3883bccfcadb8dded6/homeassistant/components/sisyphus/light.py#L94
  4. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/4deaeaeda048112c9ebd5e3883bccfcadb8dded6/homeassistant/components/shopping_list/__init__.py#L242

This comment was generated for commit ee3d0b0

@Pierre-Sassoulas
Copy link
Member

Those home assistant warnings are actual issues, this is looking very good.

@@ -326,10 +326,6 @@ def _check_format_string(self, node: nodes.Call, format_arg: Literal[0, 1]) -> N
format_arg: Index of the format string in the node arguments.
"""
num_args = _count_supplied_tokens(node.args[format_arg + 1 :])
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be voluntary though. Might need a dΓ©cision

@Pierre-Sassoulas Pierre-Sassoulas added False Negative πŸ¦‹ No message is emitted but something is wrong with the code Needs decision πŸ”’ Needs a decision before implemention or rejection labels Dec 4, 2024
@Pierre-Sassoulas Pierre-Sassoulas added this to the 4.0.0 milestone Dec 4, 2024
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 Needs decision πŸ”’ Needs a decision before implemention or rejection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect missing arguments in logging format strings
2 participants