JuliaPy / JuliaPy/PyCall.jl

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

Abierto
#847 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Julia
Estrellas
1.5k
Forks
186
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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`

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Inspect the PyCall source around the shown `haskey` and `hasproperty` definitions, starting with the existing `isdefined(Base, :hasproperty)` guard. Ensure the deprecation warning is only used when `hasproperty` exists, then verify behavior on Julia 1.0 and Julia 1.2 or higher.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
julia
Área
tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.