Support cythonized hookspecs/hookimpls

未关闭 适合新手
#830 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
71/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

从 pluggy/_manager.py 开始,阅读 _static_hook_attr,了解如何识别 hook 实现。Issue 提出了识别 Cython 函数对象的改动方案;检查现有 manager 测试中关于 hook 发现的部分,并为已编译的 hook 实现添加回归测试。回归测试通过且能够发现经过 Cython 编译的 hook,即表示完成。

由索引模型根据 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 分钟
30 天内合并 PR
13

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

pytest-dev/pluggy 的其他 Issue

查看 pytest-dev/pluggy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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