Skip to content

False positive on G001/G004 when not using a stdlib logger? #71

@q-aaronzolnailucas

Description

@q-aaronzolnailucas

A contrived minimal example that triggers for me:

class Foo:
    def info(arg) -> None:
        ...

foo: Foo = Foo()

world = "world"
foo.info("hello {world}".format(world=world))
foo.info(f"hello {world}")

Gives a G001 and G004 even though foo is quite clearly not a logger, just an object with an info method.

If I update the calls to use the extra keyword arg as flake8-logging-format requests, clearly this results in a runtime error calling Foo.info.

I ran into this issue in a non-trivial way with code which was making calls to a java logger through pyspark, which also doesn't support extra.

Could G001 be ignored whenever the object is clearly typehinted not to be a logging.Logger?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions