>Imports shouldn't have side-effects (like registering functions with flask).
Imports don't have side-effects. Using Flask's route decorators has.
>You shouldn't use globals (like the flask app).
The Flask app is just as much a global as any other class instance in any OOP language. Whether you make it a module-level object or not is your choice.
>Objects (such as the flask app) should be immutable whenever possible.
They hardly are. This is a good rule which nobody follows, and I don't think you'd gain enough advantages through this.
>You need to make sure that you import every file with a request handler, and those imports often end up unused (only imported for their side-effects), which confuses linters and other static analysis tools.
The fact that your app has import side-effects is your fault, this pattern is not at all encouraged by Flask. You probably want to use blueprints.
You're right, I hadn't seen blueprints, and they do seem to address my concerns pretty nicely.
All of the examples that I've seen (including the Flask quickstart guide, the linked post, and everything I could find on http://flask.pocoo.org/community/poweredby/ ) work by assigning the Flask app to a module-level variable (i.e. a global), then using that global at import time for all @app.route usages, so my assumption has been that that's the encouraged style. It at least seems to be pretty common. But I guess none of those examples are very big (only a few split the request handlers across multiple files), so they didn't get to a point where blueprints would be especially useful.
(Also, to be clear, when I say "imports shouldn't have side-effects", what I mean is that top-level code (which runs at import time) should ideally have no side effects.)
Imports don't have side-effects. Using Flask's route decorators has.
>You shouldn't use globals (like the flask app).
The Flask app is just as much a global as any other class instance in any OOP language. Whether you make it a module-level object or not is your choice.
>Objects (such as the flask app) should be immutable whenever possible.
They hardly are. This is a good rule which nobody follows, and I don't think you'd gain enough advantages through this.
>You need to make sure that you import every file with a request handler, and those imports often end up unused (only imported for their side-effects), which confuses linters and other static analysis tools.
The fact that your app has import side-effects is your fault, this pattern is not at all encouraged by Flask. You probably want to use blueprints.