globality-corp / flake8-logging-format

Flake8 extension to validate (lack of) logging format strings
Apache License 2.0
134 stars 21 forks source link

This module incorrectly lints against calls to the warnings module #4

Closed thanatos closed 7 years ago

thanatos commented 7 years ago

The following example,

import warnings

warnings.warn('Danger, Will Robinson!')

generates the following lint,

» flake8 example.py
example.py:3:1: G010 Logging statement uses 'warn' instead of 'warning'

There is no warning function in warnings, so the advice would break the code. It seems to be misrecognizing the statement as a logger. If there's enough context in the linter's representation of the code (like, if you have a good AST with some inference?), warnings here is a fairly obvious import of the warnings module; could perhaps those get excepted as not loggers?

jessemyers commented 7 years ago

The AST doesn't have that level of detail as far as I can tell. I added a simple name check, which feels sufficient provided you don't name your logger warnings.

See: https://github.com/globality-corp/flake8-logging-format/commit/8a6eff28a2aafb84d37c15d900c55074ed8d338c

jessemyers commented 7 years ago

I'm calling this done.