Skip to content

Support logging-check when logger is an object attribute #459

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

Closed
pylint-bot opened this issue Jan 27, 2015 · 2 comments
Closed

Support logging-check when logger is an object attribute #459

pylint-bot opened this issue Jan 27, 2015 · 2 comments
Labels

Comments

@pylint-bot
Copy link

Originally reported by: Ryan Ollos (BitBucket: rjollos, GitHub: @rjollos?)


I've been trying to configure PyLint to check for logging-not-lazy using PyLint 1.3.1. In the Trac project we have cases in which the logger is an attribute of an object.

For example, an Environment object is passed to the initializer and later the logger is utilized through a call self.env.log(...). I haven't had any success getting PyLint to detect the instances of string interpolation when running pylint --disable=all --enable=logging --logging-modules=self.env.log trac/wiki/model.py.

PyLint has no problem detecting the following case:

from trac.log import logger_factory
log = logger_factory()
log.info('Deleted version %d of page %s'
         % (version, self.name))

I originally posted this on StackOverflow.


@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Hm, using logging-modules won't work with anything other than modules. But there's definitely some sort of bug here: https://bitbucket.org/logilab/pylint/src/725447533cbfd90e5bc573eb6debf9bf94dcc799/checkers/logging.py?at=default#cl-140. The Getattr node needs to be inferred, resulting the .info function from the logging module. Checking that the name is something that logs is definitely an improvement from the current situation. If you would like to work on a pull request, I'll be happy to review it, otherwise it will take me some time before having time for a fix.

@PCManticore
Copy link
Contributor

Closing this as an instance of pylint-dev/astroid#142. Unfortunately there's no way currently for pylint to know that the said object is a logger since it relies on inference to actually detect that. Until we have either type annotation support or until we fix the aforementioned issue, there's not much we can do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants