python / python/cpython

ElementTree.iselement() returns true for the Element type

未關閉
#136,231 9 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-XML type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

According to documentation, ElementTree.iselement() check if the argument is an element object.

But it returns true also for the Element type which has all attributes of an Element instance. The way how the Element class is defined in Python suggests that this may be intentional, but the intention was lost in the documentation.

There is also an example of dataclasses.is_dataclass() which returns true both for a dataclass type and for a dataclass instance.

So, there are two ways:

  1. Fix the documentation to match the current behavior. All uses of iselement() (see #135640) should also check if the argument is a type is they need an element object.
  2. Fix the implementation to check if the argument is a type. This may break the user code that uses it to check for the Element type (I don't know if it exists) but may fix bugs in the user code which expects that iselement() works as documented.

cc @scoder

Linked PRs
  • gh-136482
  • gh-136484

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 ElementTree.iselement() 的文件與實作開始,接著檢查相關的 PR gh-136482 和 gh-136484,以及 #135640 中參照的使用處。完成的標準是釐清應該變更文件所述的行為還是實作,並一致地更新相關行為或文件。

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

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
20/100

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

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