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

Closed
wants to merge 2 commits into from

Conversation

alexprabhat99
Copy link
Contributor

@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

This comment has been minimized.

@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
@alexprabhat99 alexprabhat99 closed this by deleting the head repository Feb 20, 2025
Copy link
Contributor

πŸ€– 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/25865b4849b1a2eb5133fe3ab2fdfe3fd3b46818/homeassistant/components/sisyphus/light.py#L88
  2. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/25865b4849b1a2eb5133fe3ab2fdfe3fd3b46818/homeassistant/components/sisyphus/light.py#L94
  3. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/25865b4849b1a2eb5133fe3ab2fdfe3fd3b46818/homeassistant/components/shopping_list/__init__.py#L242
  4. logging-too-few-args:
    Not enough arguments for logging format string
    https://github.com/home-assistant/core/blob/25865b4849b1a2eb5133fe3ab2fdfe3fd3b46818/homeassistant/components/homeworks/config_flow.py#L175

This comment was generated for commit fe1792b

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