Skip to content

Conversation

@malmaud
Copy link
Contributor

@malmaud malmaud commented Jan 20, 2017

Useful for eg JuliaPy/PyCall.jl#46.

Allows instances of the same type to have different docstrings which can only be determined at runtime. Useful for interlanguage support where the same Julia type (eg PyObject) corresponds to different types in the guest language that might have different docstrings.

@tkelman tkelman added the docsystem The documentation building system label Jan 20, 2017
Copy link
Member

@MichaelHatherly MichaelHatherly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @malmaud.

var = getfield(binding.mod, binding.var)
if method_exists(getdoc, (typeof(var),))
return Base.Markdown.parse(getdoc(var))
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a bit shorter/clearer as

 function doc(binding::Binding, sig::Type = Union{})
+    if defined(binding)
+        result = getdoc(resolve(binding), sig)
+        result === nothing || return Markdown.parse(result)
+    end
     results, groups = DocStr[], MultiDoc[]

with a default getdoc(obj, sig) = nothing method. Passing sig through to getdoc as well may be useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

doc(object, sig::Type = Union{}) = doc(aliasof(object, typeof(object)), sig)

function doc(object, sig::Type = Union{})
doc(aliasof(object, typeof(object)), sig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional formatting change?

Docs.doc(binding, sig)
Returns all documentation that matches both `binding` and `sig`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap long lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@malmaud
Copy link
Contributor Author

malmaud commented Jan 23, 2017

@MichaelHatherly look good now?

"""
function doc(binding::Binding, sig::Type = Union{})
if defined(binding)
result = getdoc(resolve(binding), sig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to not call Markdown.parse here and instead just return result? That way getdocs could return a more suitable object, such as an RST object for rst-formatted python docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, that's a good call.

@malmaud malmaud merged commit 3b97b4f into master Jan 24, 2017
@malmaud malmaud deleted the jmm/dynamic_doc branch January 24, 2017 22:25
"""
getdoc(x::T, sig) -> String
Return the dynamic docstring associated with object `x`, or `nothing` to use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring doesn't explain what the sig argument is for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsystem The documentation building system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants