Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Hook tracing crashes with specced Mock arguments and results

オープン
#792 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Sandeep1519-droid がすでに取り組んでいます。

2026年10月15日 から。

  • #793 @Sandeep1519-droid による — オープン

評価

難易度
2/5
見積もり時間
半日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
devtools

調査の方向性

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日 14時間
マージ済み PR(30日)
23

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytest-dev/pluggy のほかの issue

pytest-dev/pluggy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。