Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhance import packages system#47

arab0v started this conversation inGeneral
Discussion options

condensing import statements for brevity:

from app.crud import crud_users, crud_tiers, crud_rate_limits

instead of

from app.crud.crud_users import crud_usersfrom app.crud.crud_tier import crud_tiersfrom app.crud.crud_rate_limit import crud_rate_limits

This makes imports more concise and groups related items together

You must be logged in to vote

Replies: 4 comments

Comment options

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 -------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:
Creatingcrud_all.py:

# app/crud/crud_all.pyfromcrud_usersimportcrud_usersfromcrud_tierimportcrud_tiers...

Importing what's necessary directly from crud_all:

# ------- concise imports -------fromapp.crud.crud_allimportcrud_users,crud_tiers,crud_rate_limits# ------- concise in usage -------db_user=crud_users.get(...)db_tiers=crud_tiers.get_multi(...)

Pros:

  • Would be cleaner for multiplecrud_<object> in the same file (might be worth it if it happens often)
  • Might make it easier to refactor (changing stuff incrud_all instead of doing it for everycrud_<objects>)

Cons:

  • It adds another file to maintain (you'll have to import the newcrud_<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.

You must be logged in to vote
0 replies
Comment options

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 useall 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", ...)
You must be logged in to vote
0 replies
Comment options

True, didn't think about it, but is definitely better than creating acrud_all script.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
enhancementNew feature or requesthelp wantedExtra attention is needed
2 participants
@arab0v@igorbenav
Converted from issue

This discussion was converted from issue #42 on November 14, 2023 20:48.


[8]ページ先頭

©2009-2025 Movatter.jp