alternates docstring wrapping on every run (encoding detection changes)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Start in docformatter/encode.py:72-91 and compare its encoding selection with Python tokenize.detect_encoding, using the provided repro.py to observe the alternating guesses and layouts. Add a regression check that repeatedly formats the UTF-8 fixture and verifies the file becomes unchanged with exit 0 on later runs.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Repeated standalone docformatter runs alternate between two layouts of the same UTF-8 Python file. Every run exits 3. A pre-commit hook therefore never reaches a clean result.
Environment
- Python 3.10.11, macOS 27.0
- docformatter 1.7.8
- charset-normalizer 3.4.7
- Original pre-commit environment also has tomli 2.4.1.
- Standalone reproduction below requires neither pre-commit nor Ruff, Markdown formatting, RF-DETR, or ML dependencies.
Reproduce
In an empty directory, prepare a Python 3.10 virtual environment:
python3.10 -m venv .venv
.venv/bin/python -m pip install "docformatter==1.7.8" "charset-normalizer==3.4.7"
Save this as repro.py using UTF-8. Preserve the space after the final a_b in the first comment; file contents affect encoding detection.
# a_b a_b a_b a_b a_b
class ModelWrapper:
"""``ModelWrapper`` (module-scope, importable in isolation) normalizes export-mode output to a tuple.
The wrapped model is expected to already be in export mode (``forward_export``), which returns a tuple (full
detector) or a plain list (:class:`rfdetr.export._backend._BackboneExport`) — never a dict. A dict output means
the caller forgot the mode-switch, which is a caller bug the wrapper must surface loudly rather than silently
reshape.
"""
Run the same formatter repeatedly (do not use set -e; exit 3 is the symptom):
for n in 1 2 3 4; do
.venv/bin/python -m docformatter --wrap-summaries 120 --wrap-descriptions 120 --in-place repro.py
echo "exit=$?"
done
Expected
After initial formatting, further runs leave the file unchanged and exit 0.
Actual
All four runs exit 3. Pass 2 restores the original file byte-for-byte; pass 3 restores pass 1; pass 4 restores the original again.
First-pass diff (second pass reverses it):
--- before.py
+++ after.py
@@ -3,7 +3,6 @@
"""``ModelWrapper`` (module-scope, importable in isolation) normalizes export-mode output to a tuple.
The wrapped model is expected to already be in export mode (``forward_export``), which returns a tuple (full
- detector) or a plain list (:class:`rfdetr.export._backend._BackboneExport`) — never a dict. A dict output means
- the caller forgot the mode-switch, which is a caller bug the wrapper must surface loudly rather than silently
- reshape.
+ detector) or a plain list (:class:`rfdetr.export._backend._BackboneExport`) — never a dict. A dict output means the
+ caller forgot the mode-switch, which is a caller bug the wrapper must surface loudly rather than silently reshape.
"""
Diagnostic evidence
Before successive runs, charset_normalizer.from_path("repro.py").best().encoding returns utf_8, mac_iceland, utf_8, mac_iceland for this small example. Both file states remain valid UTF-8. In the original larger file, the alternate guess was cp1250 instead.
The installed docformatter/encode.py:72-91 selects the heuristic result for decoding. The same UTF-8 em dash is consequently interpreted with a different character count, affecting line wrapping. Formatting changes the input to the next encoding guess, producing the cycle.
On the original file, a diagnostic run forcing UTF-8 decoding stabilized after one pass. Replacing em dashes with ASCII also stabilized; neither diagnostic modification is proposed as a project fix.
Python source encoding has deterministic rules: BOM or encoding cookie, otherwise UTF-8. See Python tokenize.detect_encoding. Please consider using those rules when reading Python files and add a repeated-run idempotence regression check.
Verified locally with the pinned versions above; other dependency versions and platforms untested. No upstream fix verified.
- Ngôn ngữ chính
- Python
- Star
- 598
- Fork
- 93
- Merge trung bình
- 12 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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/docformatter
-
C: convention P: bug U: high
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
PyCQA/docformatter#367 · 1 bình luận ·
-
1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its valueĐang mởC: convention P: bug U: high
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
PyCQA/docformatter#366 ·
-
fresh
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
PyCQA/docformatter#354 · 3 reaction ·
-
C: stakeholder P: enhancement U: low
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
PyCQA/docformatter#346 ·
-
C: convention P: bug U: high
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
PyCQA/docformatter#345 · 1 reaction ·
Tất cả issue của PyCQA/docformatter
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/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 85/100
kornia/kornia#5263 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Metadata correction for W16-5400Đang mởapproved correction metadata
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
acl-org/acl-anthology#10133 · 1 bình luận ·
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
BasedHardware/omi#20084 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-acceptance wg/evaluation-quality
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
vllm-project/semantic-router#4424 ·
Maintainer thường phản hồi trong vòng 1 ngày