Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Proposal: Fix `NTDebugHandler` and Deprecate `setup_logging` in `logutil.py`.

已关闭
#920 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@junkmd 已经在做这个了。

开始于 2026年9月21日。

  • #921 来自 @junkmd —— 已合并
  • #945 来自 @junkmd —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

从 comtypes/logutil.py 开始,重点查看 NTDebugHandler 和 setup_logging,然后检查它们在 server/inprocserver.py 中的使用情况。查看 issue 671 和已合并的 pull request 921 以了解背景。完成的标准是:handler 不再存在所报告的 Python 3 不兼容问题,并且 setup_logging 被明确标记为 deprecated,同时不再保留不必要的 logging 职责。

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

描述

bug tests

Summary

The logutil module contains components that are either broken, or overly broad in this project responsibilities, and have not been properly maintained or tested for a long time.
I propose to fix the NTDebugHandler class and deprecate the setup_logging function.

Problems

1. NTDebugHandler is broken due to Python 2/3 str vs bytes incompatibility

https://github.com/enthought/comtypes/blob/06879ab77bd71d86ca2601ce0af01c3e3f85de26/comtypes/logutil.py#L17-L28

  • In Python 2, str represented byte sequences, and Unicode strings were handled by a separate unicode type.
    In Python 3, str represents Unicode text, and bytes is used explicitly for byte sequences.
  • In Python 3, logging.Formatter.format, which is invoked by logging.Logger.format, always returns a Unicode string (str).
  • The NTDebugHandler.emit method has a type check (isinstance(text, str)) and passing this str directly to _OutputDebugStringA (which expects LPCSTR(bytes)) inevitably leads to errors.
  • So _OutputDebugStringW (for wide character strings) is sufficient. The existing type branching is now a source of malfunction.
2. setup_logging has excessive responsibility
  • The setup_logging is a just logging utility, unrelated to COM or Windows.
  • Such logging configuration responsibilities should ideally rest with the application developer.
3. Lack of usage and redundancy
  • These components are likely unused or used in very limited circumstances for a long time.
  • NTDebugHandler is used in server/inprocserver.py, but as discussed in https://github.com/enthought/comtypes/issues/671, the use case for inprocserver has not been confirmed for years.
    This suggests either that its breakage has gone unnoticed, or developers are using forks/custom patches.
  • The setup_logging function is not called anywhere within server/inprocserver.py, indicating its non-essential nature for the project and a weak justification for its existence.

Proposal

For the reasons outlined above, we propose to fix NTDebugHandler and deprecate the setup_logging function from this library.
This will simplify the codebase, resolve potential Python version incompatibility issues, and clarify the scope of this project responsibilities.

I plan to fix NTDebugHandler by the next release and deprecate setup_logging, with a view to removing it in a future version (likely 1.5.0).

主要语言
Python
星标
347
派生
107
平均合并
19 小时 36 分钟
30 天内合并 PR
17

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

enthought/comtypes 的其他 Issue

查看 enthought/comtypes 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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