Skip to content

Commit

Permalink
Expose docs to Julia (#354)
Browse files Browse the repository at this point in the history
* Expose docs to Julia

* Returns docstrings as Text

* Add tests
  • Loading branch information
malmaud authored and stevengj committed Jan 30, 2017
1 parent af7213b commit 2fcffd5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/PyCall.jl
Expand Up @@ -711,6 +711,14 @@ for (mime, method) in ((MIME"text/html", "_repr_html_"),
end
end

#########################################################################
# Expose Python docstrings to the Julia doc system

if isdefined(Docs, :getdoc) # Introduced in Julia .6
Docs.getdoc(o::PyObject) = Text(String(o["__doc__"]))
end


#########################################################################

include("pyeval.jl")
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Expand Up @@ -338,3 +338,15 @@ let weakdict = pyimport("weakref")["WeakValueDictionary"]
# weak references to type objects)
@test weakdict(Dict(3=>weakdict)) == Dict(3=>weakdict)
end

# Expose python docs to Julia doc system
if isdefined(Docs, :getdoc)
py"""
def foo():
"foo docstring"
return 0
"""
foo = py"foo"
# use 'content' since `Text` objects test equality by object identity
@test @doc(foo).content == "foo docstring"
end

0 comments on commit 2fcffd5

Please sign in to comment.