Hook tracing crashes with specced Mock arguments and results
维护者通常 1 天内回复
@RonnyPfannschmidt 已经在做这个了。
开始于 2026年10月17日。
评估
调研方向
The reproduction calls pm.enable_tracing() and pm.trace.root.setwriter(print) on a PluginManager, and the TypeError comes from tracing code that uses isinstance on arguments and results. Start by running the reproduction script and finding the tracing formatter or result handler it reaches. Done means a specced Mock for both str and dict is logged without changing the hook result. Pull request #793 already addresses this, so review it before starting new work.
由索引模型根据 Issue 内容生成。
描述
On main at 21c7e1672941a0cd9e3c555bf5e5007f1fbe3dc5 (Python 3.12.13), enabling hook tracing changes a successful hook call into a TypeError when an argument or first-result return value is a specced unittest.mock.Mock.
from unittest.mock import Mock
import pluggy
hookspec = pluggy.HookspecMarker("example")
hookimpl = pluggy.HookimplMarker("example")
class Spec:
@hookspec(firstresult=True)
def echo(self, value):
"""Return the value."""
class Plugin:
@hookimpl
def echo(self, value):
return value
for spec in (str, dict):
pm = pluggy.PluginManager("example")
pm.add_hookspecs(Spec)
pm.register(Plugin())
value = Mock(spec=spec)
assert pm.hook.echo(value=value) is value
pm.trace.root.setwriter(print)
pm.enable_tracing()
try:
assert pm.hook.echo(value=value) is value
except TypeError as exc:
print(spec.__name__, exc)
The string mock raises TypeError: object of type 'Mock' has no len() before the implementation runs. The dictionary mock raises TypeError: 'Mock' object is not iterable while tracing the result.
Mock(spec=...) reports its spec through __class__, so isinstance routes these objects into string formatting or dictionary metadata handling even though they are mocks. Tracing should log the mock without changing the hook result.
This report and a tested proposed fix were prepared with Codex.
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 187
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 24
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pytest-dev/pluggy 的其他 Issue
-
Plugin registry compares plugins by equality, not identity可能已有人在做 @00200200 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
pytest-dev/pluggy#760 ·
维护者通常 1 天内回复
-
deprecate passing None as a plugin instance可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
pytest-dev/pluggy#790 · 1 条评论 ·
维护者通常 1 天内回复
-
Defaulted positional-only hook parameters are forwarded as keywords可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 1-2 天 新手友好度 45/100
pytest-dev/pluggy#774 · 3 条评论 ·
维护者通常 1 天内回复
-
unregister() argument validation relies on assert可能已有人在做 @ekanshul 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 42/100
pytest-dev/pluggy#762 ·
维护者通常 1 天内回复
-
Failures during add_hookspecs / historic replay leave partial state可能已有人在做 @starx710 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 50/100
pytest-dev/pluggy#761 ·
维护者通常 1 天内回复
查看 pytest-dev/pluggy 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
lidofinance/diffyscan#239 ·
维护者通常 1 天内回复
-
area: tools documentation good first issue ready for a contributor
难度 2/5 1-3 小时 新手友好度 82/100
eyalgolan/statecraft-israel#873 · 1 条评论 ·
维护者通常 1 天内回复
-
GET rooms API returns 500 due to nonexistent Room.is_active attribute可能已有人在做 @Mars-60 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 5 天内回复
-
Harmony OPeNDAP SubSetter (HOSS) Geographic production rssmif16d 7 XYZ_PROV
难度 2/5 1-3 小时 新手友好度 62/100
nasa/harmony-autotester#341 ·