PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

Incorrect sorting #2170

Open nyudenkov opened 1 year ago

nyudenkov commented 1 year ago

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]
SarthakJaindebugger commented 1 year ago

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

bp72 commented 1 year ago

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?

nyudenkov commented 1 year ago

@bp72 I'll check, thank you

bp72 commented 9 months ago

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!