vanja109
vanja109

Reputation: 31

Import sorting error. Flake8 isort error "I001 isort found an import in the wrong position"

How can I fix it? Test error: flake8 isort found an import in the wrong position

$ python -m flake8
./api_yamdb/api/v1/views.py:9:1: I001 isort found an import in the wrong position
Error: process completed with exit code 1
from api.v1.filters import TitleFilter
from api.v1.permissions import (AuthorAdminModeratorOrReadOnly, IsAdmin,
                                IsAdminOrReadOnly)
from api.v1.serializers import (CategorySerializer, CommentSerializer,
                                ConfirmationCodeSerializer, GenreSerializer,
                                ReviewSerializer, SignUpSerializer,
                                TitleReadSerializer, TitleWriteSerializer,
                                UserEditSerializer, UserSerializer)
from api_yamdb.settings import DEFAULT_FROM_EMAIL # <--------------- ERROR!!
from django.contrib.auth.tokens import default_token_generator
from django.core.mail import send_mail
from django.db.models import Avg
from django.shortcuts import get_object_or_404
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, permissions, status, viewsets
from rest_framework.decorators import action, api_view, permission_classes
from rest_framework.response import Response
from rest_framework_simplejwt.tokens import AccessToken
from reviews.models import Category, Genre, Review, Title, User

from .mixins import CreateDestroyViewSet

I run isort . and isort views.py but there are no changes.

Upvotes: 2

Views: 3712

Answers (1)

N1ngu
N1ngu

Reputation: 3854

Just run

isort ./api_yamdb/api/v1/views.py --diff

and isort will tell you what it would expect.

This might depend on how you configured your sections ordering https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html but my gut is the api_yamdb module is local so should be among the last import instructions.

Upvotes: 3

Related Questions