isort icon indicating copy to clipboard operation
isort copied to clipboard

Incorrect sorting

Open nyudenkov opened this issue 2 years ago • 4 comments
trafficstars

isort sorts third-party socketio to local imports.

Before:

import jwt
from socketio.exceptions import ConnectionRefusedError

from src.core.auth import auth_backend

After:

import jwt

from socketio.exceptions import ConnectionRefusedError
from src.core.auth import auth_backend

My guess is that it can be because of the socketio module in the src directory:

├── src
   └── socketio

In pre-commit config:

- repo: https://github.com/timothycrosley/isort
  rev: 5.12.0
  hooks:
  - id: isort
    args: [--profile, black]

nyudenkov avatar Aug 23 '23 01:08 nyudenkov

@nyudenkov after and before code snippets looks, exactly same to me. Plz recheck.

SarthakJaindebugger avatar Oct 04 '23 14:10 SarthakJaindebugger

Hi @nyudenkov! I was able to reproduce this error like this: File structure

├── check
   └── .isort.cfg
   └── src
      └── socketio

.isort.cfg

[settings]
profile=black
src_paths=src

You are right, it indeed happens because of the local socketio module. If I change src_paths to src_paths=. then from socketio.exceptions import ConnectionRefusedError is no longer treated as a local import. May it help you with the issue?

bp72 avatar Oct 20 '23 10:10 bp72

@bp72 I'll check, thank you

nyudenkov avatar Oct 23 '23 09:10 nyudenkov

Hi @nyudenkov! Just wanted to check in and see if you had a chance to take a look. Did it help you out? Let me know if you need any further assistance!

bp72 avatar Feb 02 '24 19:02 bp72