JuliaPy / JuliaPy/PyCall.jl

deprecation message for `haskey` should only be printed on Julia 1.2 or higher

オープン
#847 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Julia
スター
1.5k
フォーク
186
PR マージ指標
30日以内にマージされた PR はありません

説明

I'm using `PyCall` v1.92.1

Near the top, it has this code:
```julia
if isdefined(Base, :hasproperty) # Julia 1.2
import Base: hasproperty
end
```

so it only overrides `hasproperty` on 1.2 where it was added to Base.

However further down, we see this code:
```julia
function haskey(o::PyObject, s::Union{Symbol,AbstractString})
Base.depwarn("`haskey(o::PyObject, s::Union{Symbol, AbstractString})` is deprecated, use `hasproperty(o, s)` instead.", :haskey)
return hasproperty(o, s)
end

# defining hasproperty on a Union triggers a method ambiguity
function pyhasproperty(o::PyObject, s::Union{Symbol,AbstractString})
if ispynull(o)
throw(ArgumentError("hasproperty of NULL PyObject"))
end
return 1 == ccall((@pysym :PyObject_HasAttrString), Cint,
(PyPtr, Cstring), o, s)
end
hasproperty(o::PyObject, s::Symbol) = pyhasproperty(o, s)
hasproperty(o::PyObject, s::AbstractString) = pyhasproperty(o, s)
```

So we're overriding `hasproperty` even when it hasn't been imported (eg: on Julia 1.0), and any calls to `haskey` display the deprecation warning.

This can be confusing because if someone were to try to use `hasproperty` on julia 1.0, they'd get an `UndefVarError` since `hasproperty` doesn't exist in `Base` and isn't exported by `PyCall`.

Perhaps we should add the `if isdefined(Base, :hasproperty) # Julia 1.2` condition before displaying the `depwarn`

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

示されている `haskey` と `hasproperty` の定義周辺にある PyCall のソースを、既存の `isdefined(Base, :hasproperty)` ガードから調査してください。`hasproperty` が存在する場合にのみ非推奨警告が使用されることを確認し、その後 Julia 1.0 と Julia 1.2 以降での動作を検証してください。

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

評価

技術スタック
julia
領域
tooling
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

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

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