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.31k stars 1.14k forks source link

E1101: (Flask) Method 'jinja_env' has no 'add_extension', 'filter' member (no-member) #2563

Open bimalkant-lauhny opened 6 years ago

bimalkant-lauhny commented 6 years ago

Steps to reproduce

  1. Run pylint hello.py (after installing flask 1.0.2), where hello.py is a simple flask app as below:
    
    from flask import Flask
    app = Flask(__name__)
    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.filters['somefilter'] = lambda s: s

@app.route('/') def hello_world(): return 'Hello, World!'


### Current behavior
pylint outputs the following for the file above:
```shell
************* Module hello
hello.py:3:0: E1101: Method 'jinja_env' has no 'add_extension' member (no-member)
hello.py:4:0: E1101: Method 'jinja_env' has no 'filters' member (no-member)

Expected behavior

It should give no error because add_extension and filters are members of Flask.jinja_env.

pylint --version output

pylint 2.1.1
astroid 2.0.4
python 3.6.6

Check the docs below for jinja environment

Flask.jinja_env Flask.jinja_env.filters jinja2.Environment.add_extension

workaround

apart from disabling, if we change code as follows, pylint shows no errors.

app.jinja_env().add_extension('jinja2.ext.do')
app.jinja_env().filters['somefilter'] = lambda s: s
aryanptl01 commented 4 years ago

Why does the workaround work?

gdubicki commented 1 year ago

The workaround did not work for me. I got this error then:

E1102: app.jinja_env is not callable (not-callable)

I used this pylintrc to disable this check:

[tool.pylint."messages control"]

disable = no-member
Pierre-Sassoulas commented 1 year ago

The solution until we make astroid better at understanding flask code is to use the generated-members option see https://pylint.pycqa.org/en/latest/user_guide/messages/error/no-member.html.