11 ms·
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: yo
by veeti 11y ago
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.
- Ao7bei3s 11y agoBut 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.