Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

RFC: Base.propertynames(x), analogous to fieldnames(typeof(x)) #25311

Merged
merged 10 commits into from
Jan 18, 2018

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Dec 29, 2017

As discussed in #24960 and #1974, it would be useful to have a propertynames(x) function, analogous to fieldnames(typeof(x)), that returns (if possible!) an array of valid symbols s for passing to getproperty(x,s) or x.s. This is especially useful for REPL tab completion.

Note that, unlike fieldnames, it needs to take an instance rather than a type, since in many cases the property names (e.g. of a dataframe or Python object) will depend on the instance.

Questions:

  • Since this is mainly for things like tab-completion, maybe it should be documented as possibly returning only "user-visible" symbols? e.g. for a LinAlg.LU, object, maybe it should return [:L,:U,:p,:P] but not "internal" fields like :ipiv?
    • if so, should the function have a different name, e.g. userpropertynames?
  • Should Base.propertynames be exported, like fieldnames?

Answers:

  • I decided to expand the api to propertynames(x, private=false): propertynames(x) by default may only return user-visible (documented) properties, but the optional private=true argument can indicate that all valid properties are requested. Tab completion uses private=false.
  • Since getproperty is not exported, I decided not to export propertynames

@stevengj stevengj added needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Dec 29, 2017
@stevengj stevengj changed the title inPropertynames RFC: Base.propertynames(x), analogous to fieldnames(typeof(x)) Dec 29, 2017
@stevengj stevengj added triage This should be discussed on a triage call and removed needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Jan 11, 2018
@JeffBezanson
Copy link
Member

Seems reasonable to me!

@JeffBezanson JeffBezanson removed the triage This should be discussed on a triage call label Jan 17, 2018
@JeffBezanson JeffBezanson added this to the 1.0 milestone Jan 17, 2018
@JeffBezanson JeffBezanson merged commit 4d93b66 into JuliaLang:master Jan 18, 2018
@stevengj stevengj deleted the propertynames branch January 18, 2018 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants