force_sort_within_sections does not sort lazy imports by module name
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Khóa sắp xếp được lấy từ section_key() trong isort/sorting.py, hàm này loại bỏ tiền tố ^from và ^import nhưng không loại bỏ lazy , nên mọi dòng lazy đều lấy lazy làm khóa. Hãy bắt đầu bằng cách tái hiện lỗi với ví dụ hai dòng trong issue, rồi đọc section_key() để xem khóa được tạo ra như thế nào. Test hiện có test_force_sort_within_sections_applies_to_lazy trong bộ test dùng ast/zlib nên che giấu lỗi này, vì vậy hãy thêm một trường hợp mà thứ tự module khác với cách tách from/import. Công việc hoàn tất khi lazy import aa đứng trước lazy from zz import x và các test hiện có vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When force_sort_within_sections is enabled, PEP 810 lazy imports are not
sorted by module name. Instead, every lazy from ... import ... line is
placed before every lazy import ... line, regardless of module names.
Steps to reproduce
With isort 9.0.2, create example.py:
lazy import aa
lazy from zz import x
and run:
$ isort --force-sort-within-sections example.py
Actual behavior
lazy from zz import x
lazy import aa
The from zz line sorts before lazy import aa, even though zz > aa.
The equivalent eager imports are ordered correctly:
$ printf 'import aa\nfrom zz import x\n' > eager.py && isort --force-sort-within-sections eager.py
import aa
from zz import x
Expected behavior
lazy import aa
lazy from zz import x
i.e. the same module-name ordering as the eager equivalent.
A slightly bigger example, all-lazy:
lazy import z
lazy from m import a
lazy import a.b
lazy from n import q as r
actual output:
lazy from m import a
lazy from n import q as r
lazy import a.b
lazy import z
while the eager equivalent is merged and sorted by module (a.b, m, n, z).
Suspected cause
section_key() in isort/sorting.py strips the ^from /^import prefixes
before deriving the sort key, but a lazy import line starts with lazy , so
neither regex matches. The module name then resolves to lazy for every lazy
import, and the full line is used as the key, which makes lazy from ...
(sorting as lazy f...) always precede lazy import ... (lazy i...).
The existing test for this option
(test_force_sort_within_sections_applies_to_lazy) uses ast/zlib, where
module order coincides with the from/straight split, so the mis-ordering is
not caught.
- Ngôn ngữ chính
- Python
- Star
- 7k
- Fork
- 838
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 19
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PyCQA/isort
-
separate_packages splits imports from the same explicitly configured packageCó thể đã có người làm @rahul05ranjan đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
length_sort with native sort order puts a longer import firstCó thể đã có người làm @simpleqt đã nhận 24 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
PyCQA/isort#2698 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Cache compiled known-module patterns across Config instancesCó thể đã có người làm @Yin123-ybh đã nhận 2 ngày trước. Đang mở
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 30/100
PyCQA/isort#2805 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
add_imports re-adds the import on every run when the file contains an `# isort: off` block (not idempotent)Có thể đã có người làm @Tanvi-007 đã nhận 6 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
PyCQA/isort#2799 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
multi_line_output=1 with include_trailing_comma leaves a dangling comma on a single importCó thể đã có người làm @beduldul đã nhận 29 ngày trước. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 15/100
PyCQA/isort#2752 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
intersystems/ipm#1338 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionĐang mởv1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
TigreGotico/text2spoken#626 ·
Maintainer thường phản hồi trong vòng 1 ngày