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)

Most upvoted comments

Ah, the issue will still be with LocalProxy, since it does set __slots__, and that’s what the g object 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.g is incorrectly marked as AppContext instead 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, LocalProxy is pretty magical, so it’s not unexpected that static analysis tools might have trouble with it.