ewe08 / Django

Django learning project
GNU General Public License v3.0
0 stars 0 forks source link

Поправить организацию импортов #31

Open drowsycoder opened 1 year ago

drowsycoder commented 1 year ago

Помните, на созвоне упоминалось про установку flake8 на максималках? (а на самом деле бывает ещё жестче) Установите, запустите и исправьте ту кучу недочетов, связанных с импортами


lyceum/catalog\admin.py:2:1: I001 isort found an import in the wrong position
lyceum/catalog\admin.py:3:1: I003 isort expected 1 blank line in imports, found 0
lyceum/catalog\admin.py:3:1: I005 isort found an unexpected missing import
lyceum/catalog\models.py:1:1: I005 isort found an unexpected missing import
lyceum/catalog\models.py:3:1: I001 isort found an import in the wrong position
lyceum/catalog\models.py:8:1: I001 isort found an import in the wrong position
lyceum/catalog\tests.py:2:1: I001 isort found an import in the wrong position
lyceum/catalog\tests.py:5:1: I001 isort found an import in the wrong position
lyceum/catalog\tests.py:6:1: I005 isort found an unexpected missing import
lyceum/catalog\views.py:2:1: I001 isort found an import in the wrong position
lyceum/catalog\views.py:3:1: I001 isort found an import in the wrong position
lyceum/catalog\views.py:4:1: I005 isort found an unexpected missing import
lyceum/catalog\views.py:5:1: I001 isort found an import in the wrong position
lyceum/catalog\views.py:6:1: I004 isort found an unexpected blank line in imports
lyceum/catalog\views.py:7:1: I005 isort found an unexpected missing import
lyceum/catalog\views.py:9:1: I003 isort expected 1 blank line in imports, found 0
lyceum/core\tests.py:3:1: I001 isort found an import in the wrong position
lyceum/core\tests.py:4:1: I005 isort found an unexpected missing import
lyceum/core\tests.py:6:1: I004 isort found an unexpected blank line in imports
lyceum/feedback\tests.py:1:1: I001 isort found an import in the wrong position
lyceum/feedback\tests.py:2:1: I005 isort found an unexpected missing import
lyceum/homepage\tests.py:1:1: I005 isort found an unexpected missing import
lyceum/homepage\tests.py:3:1: I004 isort found an unexpected blank line in imports
lyceum/homepage\tests.py:4:1: I001 isort found an import in the wrong position
lyceum/homepage\views.py:2:1: I004 isort found an unexpected blank line in imports
lyceum/homepage\views.py:3:1: I001 isort found an import in the wrong position
lyceum/lyceum\settings.py:2:1: I001 isort found an import in the wrong position
lyceum/rating\admin.py:2:1: I003 isort expected 1 blank line in imports, found 0
lyceum/rating\models.py:3:1: I004 isort found an unexpected blank line in imports
lyceum/rating\models.py:4:1: I001 isort found an import in the wrong position
lyceum/rating\tests.py:2:1: I001 isort found an import in the wrong position
lyceum/rating\tests.py:4:1: I001 isort found an import in the wrong position
lyceum/rating\tests.py:5:1: I001 isort found an import in the wrong position
lyceum/users\admin.py:4:1: I001 isort found an import in the wrong position
lyceum/users\admin.py:5:1: I005 isort found an unexpected missing import
lyceum/users\forms.py:1:1: I001 isort found an import in the wrong position
lyceum/users\forms.py:2:1: I003 isort expected 1 blank line in imports, found 0
lyceum/users\forms.py:2:1: I005 isort found an unexpected missing import
lyceum/users\models.py:2:1: I001 isort found an import in the wrong position
lyceum/users\models.py:3:1: I003 isort expected 1 blank line in imports, found 0
lyceum/users\urls.py:3:1: I001 isort found an import in the wrong position
lyceum/users\urls.py:4:1: I001 isort found an import in the wrong position
lyceum/users\urls.py:5:1: I001 isort found an import in the wrong position
lyceum/users\urls.py:6:1: I001 isort found an import in the wrong position
lyceum/users\urls.py:7:1: I001 isort found an import in the wrong position
lyceum/users\urls.py:8:1: I005 isort found an unexpected missing import
lyceum/users\urls.py:8:1: I005 isort found an unexpected missing import
lyceum/users\urls.py:8:1: I005 isort found an unexpected missing import
lyceum/users\urls.py:8:1: I005 isort found an unexpected missing import
lyceum/users\urls.py:8:1: I005 isort found an unexpected missing import
lyceum/users\views.py:1:1: I001 isort found an import in the wrong position
lyceum/users\views.py:2:1: I001 isort found an import in the wrong position
lyceum/users\views.py:3:1: I001 isort found an import in the wrong position
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:4:1: I005 isort found an unexpected missing import
lyceum/users\views.py:7:1: I001 isort found an import in the wrong position
lyceum/users\views.py:8:1: I005 isort found an unexpected missing import
drowsycoder commented 1 year ago

Недоработано

Локальные импорты в пределах одного приложения стоит оформлять как указано в доках (https://docs.djangoproject.com/en/3.2/internals/contributing/writing-code/coding-style/#imports), а также советуют в туториалах (https://learndjango.com/tutorials/django-best-practices-imports):

# local Django
from .models import LogEntry

То есть

from catalog.models import Category, Item, Photo, Tag

в catalog.admin это не норм

Или вот это что?

from about import views

(Это именно в пределах одного приложения; с импортами относительно других своих же приложений, пусть и в рамках одного проекта, так делать не надо) Django

drowsycoder commented 1 year ago

Тоже недокручено. Например, в приложении catalog обращение к себе же from catalog.models import Category, Item, Tag -> from ..models import Category, Item, Tag