Support cythonized hookspecs/hookimpls

オープン 初心者向け
#830 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
71/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

pluggy/_manager.pyから始めて、_static_hook_attrを読み、フック実装がどのように認識されるかを確認してください。Issueでは、Cythonの関数オブジェクトを認識するための変更案が示されています。フックの検出に関する既存のmanagerテストを確認し、コンパイルされたフック実装の回帰テストを追加してください。回帰テストが成功し、Cythonでコンパイルされたフックが検出されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

I have a project with hookimpls located in a .pyx module that is compiled to a native extension. With v1.7.0, the PluginManager doesn't discover the hookimpls in the compiled module, because inspect.isfunction() doesn't see cyfunction objects as functions (in pre-1.7.0 versions, inspect.isroutine() treated them as builtin functions). Is it deliberate or did it just slipped through unnoticed (since this is admitted a rare use case)? Below a simple patch that adds back the functionality without resorting to isroutine - if you agree that supporting cythonized functions is a valid use case, happy to turn it into a PR with a regression test.

--- a/pluggy/_manager.py
+++ b/pluggy/_manager.py
@@ -61,6 +61,12 @@ def _instance_dict(obj: object) -> dict[str, Any]:
     return instance_dict if isinstance(instance_dict, dict) else {}
 
 
+def _is_function_or_cyfunction(obj: object) -> bool:
+    return inspect.isfunction(obj) or type(obj).__name__ in (
+        "cython_function_or_method",
+        "fused_cython_function",
+    )
+
 def _static_hook_attr(
     obj: object, name: str
 ) -> tuple[object, Callable[..., object]] | None:
@@ -93,7 +99,7 @@ def _static_hook_attr(
         if value is not _ABSENT:
             if isinstance(value, types.MethodType):
                 return value.__func__, value
-            if inspect.isfunction(value):
+            if _is_function_or_cyfunction(value):
                 return value, value
             return None
 
@@ -105,7 +111,7 @@ def _static_hook_attr(
         return static, cast(Callable[..., object], static.__get__(owner, owner))
     if isinstance(static, types.MethodType):
         return static.__func__, static
-    if inspect.isfunction(static):
+    if _is_function_or_cyfunction(static):
         if inspect.isclass(obj) or inspect.ismodule(obj):
             return static, static
         return static, static.__get__(obj, type(obj))
主要言語
Python
スター
1.7k
フォーク
200
平均マージ
10時間 4分
マージ済み PR(30日)
13

環境構築

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

はじめの一歩

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

pytest-dev/pluggy のほかの issue

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

似ている issue

Python の issue をもっと見る

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

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