flask: Assigning to attribute flask.g.[...] not defined in class slots (assigning-non-slot)
Thanks for a recent release of flask which looks great. 🎉 Just started testing it out.
This is not directly a bug afaik, but our CI started failing on the new release of flask and werkzeug.
Following the flask documentation, it appears the recommended way of setting new attributes to flask.g is simply doing flask.g.some_attribute = some_value.
This example code
from flask import g
g.some_attribute = 42
gives no pylint warning when used together with pip install "flask<2" "werkzeug<2", however after pip install --upgrade flask werkzeug the same code gives the following pylint warning:
test_pylint.py:3:0: E0237: Assigning to attribute 'some_attribute' not defined in class slots (assigning-non-slot)
Any recommended code change that should be done related to setting attributes on the namespace object flask.g, or would the best recommendation be to silence pylint when used with newest flask + werkzeug?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (9 by maintainers)
Ah, the issue will still be with
LocalProxy, since it does set__slots__, and that’s what thegobject really is. That’s probably still going to have to be reported to mypy and pylint. The fact that it sets__slots__is not new, and it defines__setattr__, so not sure why the error started.It looks like the type of
flask.globals.gis incorrectly marked asAppContextinstead of_AppCtxGlobals, which I can fix. However, neither of them set__slots__, so I’m not sure why that’s the error.That sounds like an issue with pylint. Unfortunately,
LocalProxyis pretty magical, so it’s not unexpected that static analysis tools might have trouble with it.