Enhance import packages system #47
Replies: 4 comments
-
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: # ------- verbose imports -------
from app.crud.crud_users import crud_users
from app.crud.crud_tier import crud_tiers
from app.crud.crud_rate_limit import crud_rate_limits
# ------- more concise in usage -------
db_user = crud_users.get(...)
db_tiers = crud_tiers.get_multi(...)
... Proposed style: # ------- 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 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: # app/crud/crud_all.py
from crud_users import crud_users
from crud_tier import crud_tiers
... Importing what's necessary directly from crud_all: # ------- concise imports -------
from app.crud.crud_all import crud_users, crud_tiers, crud_rate_limits
# ------- concise in usage -------
db_user = crud_users.get(...)
db_tiers = crud_tiers.get_multi(...) Pros:
Cons:
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. |
Beta Was this translation helpful? Give feedback.
-
thanks for your patient,
to
|
Beta Was this translation helpful? Give feedback.
-
True, didn't think about it, but is definitely better than creating a |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
condensing import statements for brevity:
instead of
This makes imports more concise and groups related items together
Beta Was this translation helpful? Give feedback.
All reactions