Re:Discover Flask
by ergo14 on Sunday February 21, 2016 @05:58AM
(#11144052)
Flask is using globals everywhere, and for very long time did not support Python 3.x.
[ Parent
| on HN ]
Re:Discover Flask
by rockyearth on Sunday February 21, 2016 @07:44AM
(#11144290)
Although most of the methods are globally bound to the current request, Flask is thread safe and I can't see any problem with it. (except that it encourages beginners to use globals, which might be process and thread-unsafe).
I really don't see any benefit or sense in the Flask way of exposing request state through imported globals. It makes testing of views unnecessarily complex: you have to either patch the import or set up the thread local context in every test. And like you mentioned, it encourages unnecessary coupling.
It would be so much simpler to just have a request argument passed to each view.
But then you have to explicitly pass the context to everything you call.
Dynamic scoping would solve this problem (and similar problems, like dependency injection), but Python doesn't have that.
Flasks way emulates it as well as possible.