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

Can we have hasdefault or alldefaults methods? #113

Open
singularitti opened this issue Dec 18, 2019 · 4 comments
Open

Can we have hasdefault or alldefaults methods? #113

singularitti opened this issue Dec 18, 2019 · 4 comments

Comments

@singularitti
Copy link
Contributor

singularitti commented Dec 18, 2019

If we have a type that is not entirely fed with default values, is there a method that can tell users which fields have default values and which fields do not? For example,

@with_kw A
    a = 1
    b
    c = 2.0
    d
    e = "test"
end

hasdefault(A, :a)  #  true
hasdefault(A, :b)  # false
alldefaults(A)  # (:a, :c, :e)
nondefaults(A)  # (:b, :d)
@mauro3
Copy link
Owner

mauro3 commented Dec 18, 2019

In principle this is covered by the auto-generated doc-strings. Although they don't work too well:

julia> "Some Doc"
       @with_kw struct A
           a = 1
           b
           c = 2.0
           d
           e = "test"
       end
A

help?> A
search: A Any any all abs ARGS ans axes atan asin asec any! all! acsc acot acos abs2 Array atanh atand asinh asind asech asecd ascii angle acsch acscd

  Some Doc

help?> A.a
  Default: 1

help?> A.b
  A has fields a, b, c, d, and e.

So, this should be fixed . But I'm against adding those query methods.

@singularitti
Copy link
Contributor Author

This is not for documenting issues. It is for programming issues. I want to filter all the fields that have default values and do things to them. It is not possible and ugly to list them one by one for a type with many (>20) fields.

@mauro3
Copy link
Owner

mauro3 commented Dec 19, 2019

I see. This seems pretty niche and is not something I ever see myself using, so I'm not interested in having to support this. However, I think this could be implemented with a post-processing function, for which support is envisaged, at some point. Something along what's mentioned in #52.

@alhirzel
Copy link

alhirzel commented May 3, 2021

In addition to this issue topic, it is sometimes useful to have access to the default values for some fields.

This capability can allow for more rich integration when automatically populating structures (e.g. custom ArgParse.jl integrations).

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

No branches or pull requests

3 participants