Pylint false positive for Flask's "app.logger": E1101: Method 'logger' has no 'debug' member (no-member)


Using flask’s app.logger member functions (such as app.logger.error) causes pylint to report E1101 (no-member) errors, even though these members of app.logger are defined at runtime.

This can be reproduced by using the following files:

import flask
app = flask.Flask(__name__)

def say_hello():
    app.logger.debug('A debug message')
    app.logger.error('An error message')
    return 'hello'



Sample commands for reproducing the issue, using virtualenv:

(Python 3.5 is used here, but the issue is not specific to that version)

virtualenv --python=python3.5 env
source env/bin/activate
pip install pip==18.0
pip install -r requirements.txt

And finally, running pylint:

pylint -E app

Returns these errors:

************* Module app E1101: Method 'logger' has no 'debug' member (no-member) E1101: Method 'logger' has no 'error' member (no-member)

Is there a good way to avoid these false positives?


A solution to prevent these false positives, via pylint plugins:

import sys

from astroid import MANAGER, scoped_nodes, extract_node
from astroid.builder import AstroidBuilder

def register(_linter):

def transform(f):
    if == 'logger':
        for prop in ['debug', 'info', 'warning', 'error', 'addHandler']:
            f.instance_attrs[prop] = extract_node('def {name}(arg): return'.format(name=prop))

MANAGER.register_transform(scoped_nodes.FunctionDef, transform)

This workaround prevents linting errors on app.logger.debug,, app.logger.warning, app.logger.error and app.logger.addHandler.

In order to be used, the file needs to be loaded using the --load-plugins command line option:

PYTHONPATH="." pylint -E app --load-plugins pylintplugins

or by including the following line in the pylintrc configuration file:


Answered By – Odysseas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published