deprecation message for `haskey` should only be printed on Julia 1.2 or higher
- Dominant language
- Julia
- Stars
- 1.5k
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
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`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.