E1101 on Flask.logger.<method>
Opened this issue · 5 comments
Steps to reproduce
- create
minimal.py
:
#pylint: disable=missing-docstring,invalid-name
from flask import Flask
app = Flask(__name__)
@app.route('/')
def _foo():
app.logger.debug('bar')
return 'baz'
- run
pylint minimal.py
Current behavior
************* Module minimal
minimal.py:9:4: E1101: Method 'logger' has no 'debug' member (no-member)
Expected behavior
No errors
pylint --version output
pylint 2.1.1
astroid 2.0.4
Additional information
This is for Flask version 1.0.2, which is current as of the date of this report.
Thanks for reporting an issue! The thing with flask
is that we always had problems inferring flask
given the amount of metaprogramming it relies on.
I'm still seeing this problem with flask==2.2.2
and pylint==2.16.0
, when using APP.logger.info(...)
.
Typing is very well-defined (https://github.com/pallets/flask/blob/4ddb3f73baa5b60ed83d6bb48d0d447a0d8ab492/src/flask/app.py#L772), and using directly a log = logging.getLogger()
class with log.info(...)
does not produce the no-member false positive, so why is this flagged incorrectly in the case of Flask?
pylint does not use typing but its inference (which fail is the code is too dynamic), see #4813
I see. Is there a specific config in .pylintrc
that I can set to specifically ignore instances of Flask.logger.<method>
? There are too many in the code base to add pylint disable comments everywhere.
For anyone finding this issue, my current workaround is by defining the following in .pylintrc
[TYPECHECK]
generated-members=
logger.debug,
logger.info,
logger.warning,
logger.error,
logger.exception,
app.logger.debug,
app.logger.info,
app.logger.warning,
app.logger.error,
app.logger.exception,
APP.logger.debug,
APP.logger.info,
APP.logger.warning,
APP.logger.error,
APP.logger.exception