Skip to content

Rule G004 doesn't work with inline instantiated logger #11031

@Spenhouet

Description

@Spenhouet

Given the following code:

logger = Logger()
logger.warning(f"{database_name} database not available.")

the ruff linter will complain about G004 ("Logging statement uses f-string").

But given an inline instantiation of the logger, there is no such warning.

Logger().warning(f"{database_name} database not available.")

The "G" rule (flake8-logging-format) needs to be enabled.
My ruff version is 0.3.1.
I searched for G004 but none of the existing issues cover this. The answer might be similar to #6353 (comment) but I do think that this is something which could be covered.

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions