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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPS412: Flask App Factory Pattern Incompatibility #1108
Comments
I can mention this Flask Mega-Tutorial as reference and backup for my suggestion. |
Why not |
@sobolevn that sounds legit, but dont cover the other case, reduce boilerplate when importing libraries
It dont cover a subpackage case, for example, a Flask Blueprint Package, where the "Package" its a representation of the Blueprint, and like so, sounds good to init the Blueprint required stuff in its init.py. Following your solution this can be solved with a blueprint.py in each Blueprint Subpackage, and that is an overkill from my point of view. this also means that for import the created Blueprint we must do: from application.<blueprint-name>.blueprint import <blueprint-name>_bp Instead of just from application.<blueprint-name> import <blueprint-name>_bp |
In our rules And namespaces are always a great idea! We need more of those! |
Got it @sobolevn. can you give me some insights or recommendations about how i can refactor my code? Go for the application..bluepirnt.py for init the blueprint related stuff? In other python applications, should i keep the init.py for expose the subpackage internals more directly to the namespace? Just looking for a clear path to resolve this, thanks in advance! |
Just rename your Does this solve your problem? |
just one last question: What i must do with the imports in the init.py:
from deepbay.denseblock import DenseBlock
from deepbay import DenseBlock In the last case, WPS will still mark unused imports warning. What approach you recommend to me? Thanks for your time, sorry for pick it up a bit. |
I always keeps imports out of |
I am going to close this as solved, if you have any other questions - please, feel free to ask! |
Rule request
Thesis
Change WPS412 to accept logic inside init.py files.
Reasoning
Flask App Factory Pattern depend on the main package _init.py for define the create_app() function, this is the natural location for this type of logic. Check this example Flask project's init.py
Maybe this can be a problem too for when a subpackage if defined, and is natural to expose its internals in the init.py for avoid boiler plate, for example:
Change
To
If my reasoning is not good enough, feedback will be appreciated, thanks!
The text was updated successfully, but these errors were encountered: