pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.32k stars 1.14k forks source link

E1101 on Flask.logger.<method> #2586

Open jamesjren opened 6 years ago

jamesjren commented 6 years ago

Steps to reproduce

  1. 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'

2. 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.
PCManticore commented 5 years ago

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.

fmigneault commented 1 year ago

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?

Pierre-Sassoulas commented 1 year ago

pylint does not use typing but its inference (which fail is the code is too dynamic), see #4813

fmigneault commented 1 year ago

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.

fmigneault commented 1 year ago

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