EllipsisMiddleTruncate exceeds requested width when only the ellipsis fits

未關閉 適合新手
#722 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@hugosmoreira 已經在處理了。

開始於 2026年10月26日。

  • #724 來自 @hugosmoreira —— 未關閉
  • #726 來自 @MateehUllah —— 未關閉

評估

難度
1/5
預估耗時
1-3 小時
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cli

研究方向

從fire/formatting.py開始,檢查EllipsisMiddleTruncate,重點關注長度為零的後半部分,以及不進行截斷的邊界。重現 issue 中的兩個範例,接著確認輸出不超過要求的寬度,並保留剛好容納得下的字串。

由索引模型根據 Issue 內容生成。

描述

EllipsisMiddleTruncate returns more characters than the requested width when available_space is 3. It also modifies strings that already fit exactly within the specified width.

Steps to reproduce
from fire import formatting

print(formatting.EllipsisMiddleTruncate('abcdefghij', 3, 80))
# Actual: '...abcdefghij'
# Expected: '...'

print(formatting.EllipsisMiddleTruncate('abcd', 4, 80))
# Actual: '...d'
# Expected: 'abcd'
Cause

The expression text[-second_half_len:] returns the entire string when second_half_len is zero. The no-truncation check also uses < instead of <=.

Expected behavior

Output should respect the available width, and strings that already fit should remain unchanged.

Verification

Reproduced using the implementation from fire/formatting.py.

主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

google/python-fire 的其他 Issue

查看 google/python-fire 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。