You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually more of a coding style issue, since this change would indeed make the import statements more concise, but would make the code in general more verbose:
Current style:
# ------- verbose imports -------fromapp.crud.crud_usersimportcrud_usersfromapp.crud.crud_tierimportcrud_tiersfromapp.crud.crud_rate_limitimportcrud_rate_limits# ------- more concise in usage -------db_user=crud_users.get(...)
db_tiers=crud_tiers.get_multi(...)
...
Proposed style:
# ------- more concise imports -------fromapp.crudimportcrud_users, crud_tiers, crud_rate_limits# ------- more verbose in usage -------db_user=crud_users.crud_users.get(...)
db_tiers=crud_tier.crud_tiers.get_multi(...)
...
To be honest, I'm not completely sold on any of the options. The advantage of the proposed style would be knowing exactly where the crud_ class comes from, but since it always comes from a crud_ file, I don't think it would do any good.
A third possibility would be:
Creating crud_all.py:
Would be cleaner for multiple crud_<object> in the same file (might be worth it if it happens often)
Might make it easier to refactor (changing stuff in crud_all instead of doing it for every crud_<objects>)
Cons:
It adds another file to maintain (you'll have to import the new crud_<object> to this file every time you create one)
Might cause circular imports, specially for beginners using
Reduces clarity: you do not know exactly where the import is coming from (maybe this one isn't as strong since - again - the original module and the class have the same name)
I don't think the added complexity is necessary for smaller projects, but maybe it is for larger projects. I'll leave this issue open for some time so you (or someone else) can keep this discussion going until I'm actually certain what to do.
thanks for your patient,
yeah i totally agree its more coding style, you can close this issue if you see its not reasonable or doesn't consider as enhancement
you could use all in the __init__.py it will become
from this
# ------- more concise imports -------
from app.crud import crud_users, crud_tiers, crud_rate_limits
# ------- more verbose in usage -------
db_user = crud_users.crud_users.get(...)
db_tiers = crud_tier.crud_tiers.get_multi(...)
to
from app.crud import crud_users, crud_tiers, crud_rate_limits
# ------- more verbose in usage -------
db_user = crud_users.get(...)
db_tiers = crud_tiers.get_multi(...)
__inti__.py file will look like
from .crud_users import crud_users
...
__all__ = ("crud_users", ...)
I'll convert it to a discussion because it may be useful for people who choose this style, but I think it's better leaving the decision to who's using the boilerplate.
Activity
igorbenav commentedon Nov 14, 2023
Hey, @YousefAldabbas, thanks again for the issue!
This is actually more of a coding style issue, since this change would indeed make the import statements more concise, but would make the code in general more verbose:
Current style:
Proposed style:
To be honest, I'm not completely sold on any of the options. The advantage of the proposed style would be knowing exactly where the crud_ class comes from, but since it always comes from a crud_ file, I don't think it would do any good.
A third possibility would be:
Creating
crud_all.py:Importing what's necessary directly from crud_all:
Pros:
crud_<object>in the same file (might be worth it if it happens often)crud_allinstead of doing it for everycrud_<objects>)Cons:
crud_<object>to this file every time you create one)I don't think the added complexity is necessary for smaller projects, but maybe it is for larger projects. I'll leave this issue open for some time so you (or someone else) can keep this discussion going until I'm actually certain what to do.
arab0v commentedon Nov 14, 2023
thanks for your patient,
yeah i totally agree its more coding style, you can close this issue if you see its not reasonable or doesn't consider as enhancement
you could use all in the
__init__.pyit will becomefrom this
to
__inti__.pyfile will look likeigorbenav commentedon Nov 14, 2023
True, didn't think about it, but is definitely better than creating a
crud_allscript.igorbenav commentedon Nov 14, 2023
I'll convert it to a discussion because it may be useful for people who choose this style, but I think it's better leaving the decision to who's using the boilerplate.