Skip to content

Commit 5f9e58a

Browse files
author
Christopher Doris
committed
getdoc returns nothing when given null
1 parent 479cb6e commit 5f9e58a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/Py.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ Base.powermod(x::Number, y::Py, z::Number) = pypow(x, y, z)
451451
Base.powermod(x::Py, y::Number, z::Number) = pypow(x, y, z)
452452

453453
# documentation
454-
function Base.Docs.getdoc(x::Py, @nospecialize(sig))
454+
function Base.Docs.getdoc(x::Py, @nospecialize(sig)=Union{})
455+
pyisnull(x) && return nothing
455456
parts = []
456457
inspect = pyimport("inspect")
457458
# head line

test/abstract.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@
207207
@test !pyin(-1, x)
208208
@test !pyin(pybuiltins.None, x)
209209
end
210+
@testset "getdoc" begin
211+
@test Base.Docs.getdoc(Py(nothing)) isa Markdown.MD
212+
@test Base.Docs.getdoc(Py(12)) isa Markdown.MD
213+
@test Base.Docs.getdoc(pybuiltins.int) isa Markdown.MD
214+
@test Base.Docs.getdoc(PythonCall.PyNULL) === nothing
215+
end
210216
end
211217

212218
@testset "iter" begin

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using PythonCall, Test, Dates, Aqua
1+
using PythonCall, Test, Dates, Aqua, Markdown
22

33
# The unbound_args test fails on methods with signature like foo(::Type{Tuple{Vararg{V}}}) where V
44
# Seems like a bug.

0 commit comments

Comments
 (0)