Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add Base.hasproperty? #28850

Closed
stevengj opened this issue Aug 23, 2018 · 2 comments
Closed

add Base.hasproperty? #28850

stevengj opened this issue Aug 23, 2018 · 2 comments
Labels
feature Indicates new feature / enhancement requests

Comments

@stevengj
Copy link
Member

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

@stevengj stevengj added the feature Indicates new feature / enhancement requests label Aug 23, 2018
@ararslan
Copy link
Member

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

@vtjnash
Copy link
Member

vtjnash commented Aug 23, 2018

Agreed. I think the fallback may be isdefined though.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

3 participants