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

Fallback to getproperty in at-doc #30835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fallback to getproperty in at-doc #30835

wants to merge 2 commits into from

Conversation

tkf
Copy link
Member

@tkf tkf commented Jan 25, 2019

Before this PR

help?> Some(123).value
ERROR: MethodError: no method matching Base.Docs.Binding(::Some{Int64}, ::Symbol)
Closest candidates are:
  Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
Stacktrace:
 [1] top-level scope at none:0

After this PR

help?> Some(123).value
  Int64 <: Signed

  64-bit signed integer type.

I guess there are other possible behaviors (e.g., show field docstring if found) but I think getproperty is a good default fallback.

ref JuliaPy/PyCall.jl#635

base/docs/bindings.jl Outdated Show resolved Hide resolved
@fredrikekre
Copy link
Member

This could alternatively retrieve the fielddoc I guess?

@tkf
Copy link
Member Author

tkf commented Jan 30, 2019

Yeah, I can imagine extending `binding` to something like
binding(x, v) =
    if v isa Symbol && hasfielddoc(x, v)    # pseudo code
        fielddoc(x, v)                      # pseudo code
    else
        getproperty(x, v)
    end

but I don't know if there are APIs like hasfielddoc and fielddoc. REPL.fielddoc seems do it a bit differently. I thought falling-back to getproperty is a good start for extending it.

@tkf
Copy link
Member Author

tkf commented Jan 31, 2019

Actually, retrieving the doc in binding doesn't make sense as it should happen in Docs.doc, not Docs.binding. Maybe we should extend Binding from

struct Binding
    mod::Module
    var::Symbol
end

to

struct Binding
    thing  # allow any object, not just a `Module`
    var::Union{Symbol, String}
end

or maybe even to

struct Binding
    thing
    accessor # e.g., `:a`, `"b"`, `(:a, :b, :c)`
end

?

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.

None yet

3 participants