JuliaPy / JuliaPy/PyCall.jl

zero-arg call to Python `super()` not working

未关闭
#409 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Julia
星标
1.5k
派生
186
PR 合并指标
30 天内没有已合并 PR

描述

As the title says, the zero-arg version of `super()` doesn't work,

```julia
julia> @pydef type Foo
__str__(self) = pybuiltin(:super)()[:__str__]()
end
PyObject

julia> Foo()[:__str__]()
ERROR: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL))
RuntimeError('super(): no arguments',)
File "PyCall", line 1, in

Stacktrace:
[1] pyerr_check at /home/marius/.julia/v0.6/PyCall/src/exception.jl:56 [inlined]
[2] pyerr_check at /home/marius/.julia/v0.6/PyCall/src/exception.jl:61 [inlined]
[3] macro expansion at /home/marius/.julia/v0.6/PyCall/src/exception.jl:81 [inlined]
[4] #_pycall#66(::Array{Any,1}, ::Function, ::PyCall.PyObject) at /home/marius/.julia/v0.6/PyCall/src/PyCall.jl:620
[5] #pycall#70(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}) at /home/marius/.julia/v0.6/PyCall/src/PyCall.jl:642
[6] #call#71 at /home/marius/.julia/v0.6/PyCall/src/PyCall.jl:645 [inlined]
[7] (::PyCall.PyObject)() at /home/marius/.julia/v0.6/PyCall/src/PyCall.jl:645
```

although the manual version is fine,

```julia
julia> @pydef type Bar
__str__(self) = pybuiltin(:super)(Bar,self)[:__str__]()
end
PyObject

julia> Bar()[:__str__]()
""
```

I'm guessing what's happening is described by [this](https://stackoverflow.com/a/39313448/1078529) answer,

> The zero-argument form of super requires that the method containing it have an explicit (i.e., non-varargs) first argument

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先,在生成的 __str__ 方法中使用 pybuiltin(:super) 重现 @pydef 示例,并比较零参数形式和显式参数形式。跟踪这些入口点如何调用 Python,并确定使零参数形式正常工作所需的内容;当第一个示例不再引发 RuntimeError,同时手动形式仍能正常工作时,即视为完成。

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

评估

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

把新 issue 发到你的邮箱

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