New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning to attribute flask.g.[...] not defined in class slots (assigning-non-slot) #4020
Comments
@app.before_request
def set_attr():
g.some_attribute = 42 Or if you really need to test this without a request: with app.app_context():
g.some_attribute = 42 |
@davidism Thanks for quick answer. We are in practice doing it in an |
That sounds like an issue with pylint. Unfortunately, |
Note, it also causes a failure in mypy with |
It looks like the type of |
@davidism if you push a test branch I'd be happy to test with my app. |
Ah, the issue will still be with |
The The "has no attribute" issue needs to be reported to mypy. It seems like both should allow any attribute since the classes define I updated the type annotation, but both messages are still produced, I don't think there's anything we can do. |
I think anyone using either |
I assume this is also the reason for a mypy error I鈥檓 seeing since upgrading to Flask 2.0.0:
|
After experimenting, it looks like mypy understands that an object is a namespace for arbitrary attributes if |
Yea, the SimpleNamespace is typed this way. I'm experimenting with Quart at the moment. |
@davidism this fixed the CI on the LVFS, thanks! |
I'm in a similar seats here, trying to upgrade to 2.0.1 though: @app.before_request
def before_request():
flask.g.start_time = time.time() Getting
We are using attribute assignment to figure out how long the request takes and report it to datadog. Any ideas on what we should be doing instead since it's 2.0.1 and not fixed for us yet? |
Yes, that's a pylint error, not a mypy error. Nothing we can do about it, report it to pylint. |
FWIW and future reference (if to be reported in |
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
andwerkzeug
.Following the flask documentation, it appears the recommended way of setting new attributes to
flask.g
is simply doingflask.g.some_attribute = some_value
.This example code
gives no
pylint
warning when used together withpip install "flask<2" "werkzeug<2"
, however afterpip install --upgrade flask werkzeug
the same code gives the followingpylint
warning: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 silencepylint
when used with newestflask
+werkzeug
?The text was updated successfully, but these errors were encountered: