python / python/cpython

IDLE: ScrolledCanvas.zoom_height calls idlelib.zoomheight.zoom_height, which has not existed since 2019

未关闭
#157,762 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-IDLE type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

idlelib.tree.ScrolledCanvas.zoom_height calls a module-level function that has not existed since 2019, so the binding raises as soon as it fires.

Where: Lib/idlelib/tree.py, ScrolledCanvas.zoom_height (line 459 on main), bound to <Alt-2> on the canvas:

def zoom_height(self, event):
    zoomheight.zoom_height(self.master)

idlelib/zoomheight.py has had no module-level zoom_height since the Zoom Height rework (gh-81220, PRs #13576 and #13678, 2019): zooming is now ZoomHeight(editwin).zoom_height(), which only reads editwin.top.

Reproduce (3.13.5, but the call is the same on main):

>>> from idlelib import zoomheight
>>> zoomheight.zoom_height
AttributeError: module 'idlelib.zoomheight' has no attribute 'zoom_height'. Did you mean: 'ZoomHeight'?

Pressing Alt-2 in a tree window (Path Browser, Module Browser, the debugger's stack viewer) raises the same AttributeError out of the Tk callback.

Proposed fixZoomHeight needs only the toplevel window of what it zooms:

+from types import SimpleNamespace
+
 from idlelib import zoomheight
@@
     def zoom_height(self, event):
-        zoomheight.zoom_height(self.master)
+        # ZoomHeight needs only the toplevel window of what it zooms.
+        top = self.canvas.winfo_toplevel()
+        zoomheight.ZoomHeight(SimpleNamespace(top=top)).zoom_height()
         return "break"

Checked by calling ScrolledCanvas.zoom_height from main's sources against a stand-in toplevel: the current code raises AttributeError; the fixed code maximizes the window height (400x300+10+20 -> 400x760+10+0).

If a SimpleNamespace stand-in is not wanted here, ZoomHeight.zoom_height could instead take the toplevel directly; happy to send a PR either way.

Environment: Windows 11, CPython 3.13.5; the line is unchanged on main.


Found while auditing installed code with a verification tool I am building; the reproduction above was run on the version named, and the proposed fix was applied to a local copy and run as well. Report drafted with AI assistance.

Linked PRs
  • gh-157772

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Lib/idlelib/tree.py 中的 ScrolledCanvas.zoom_height 开始,并将其与 idlelib/zoomheight.py 中 ZoomHeight.zoom_height 的实现进行比较。在树窗口中重现 Alt-2 操作,然后验证修正后的调用不再引发 AttributeError,并将顶层窗口缩放到其高度。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
desktop
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。