add Base.hasproperty?
stevengj opened this issue · comments
I just realized that we don't have a hasproperty(x, s)
function, analogous to haskey
. We could define one with the default definition:
hasproperty(x, s::Symbol) = s in propertynames(x)
This came up in https://github.com/JuliaPy/PyCall.jl/pull/517/files#r212317623
Relatedly, a hasfield
function to accompany getfield
/setfield!
may be nice. This definition actually works for that:
hasfield(T::DataType, name::Symbol) = fieldindex(T, name, false) > 0
Agreed. I think the fallback may be isdefined
though.