deprecation message for `haskey` should only be printed on Julia 1.2 or higher
- Langage dominant
- Julia
- Étoiles
- 1.5k
- Forks
- 186
- Métriques de merge des PR
- Aucune PR mergée en 30 j
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`
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Examinez le code source de PyCall autour des définitions indiquées de `haskey` et `hasproperty`, en commençant par la garde existante `isdefined(Base, :hasproperty)`. Vérifiez que l’avertissement de dépréciation n’est utilisé que lorsque `hasproperty` existe, puis vérifiez le comportement avec Julia 1.0 et Julia 1.2 ou ultérieure.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- julia
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 45/100