Skip to content

Commit d223561

Browse files
author
Christopher Doris
committed
allow builtins.help to be missing
1 parent bc06879 commit d223561

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/abstract/builtins.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ export pyprint
1313
1414
Equivalent to `help(x)` in Python.
1515
"""
16-
pyhelp() = (pydel!(pybuiltins.help()); nothing)
17-
pyhelp(x) = (pydel!(pybuiltins.help(x)); nothing)
16+
function _pyhelp(args...)
17+
pyisnone(pybuiltins.help) && error("Python help is not available")
18+
pydel!(pybuiltins.help(args...))
19+
nothing
20+
end
21+
pyhelp() = _pyhelp()
22+
pyhelp(x) = _pyhelp(x)
1823
export pyhelp
1924

2025
"""

src/concrete/consts.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ pybuiltins
182182
export pybuiltins
183183

184184
for k in BUILTINS
185-
push!(INIT_CONSTS_CODE, :(pycopy!(pybuiltins.$k, pybuiltinsmodule.$k)))
185+
if k == :help
186+
# help is only available in interactive contexts (imported by the 'site' module)
187+
# see: https://docs.python.org/3/library/functions.html#help
188+
# see: https://github.com/cjdoris/PythonCall.jl/issues/248
189+
push!(INIT_CONSTS_CODE, :(pycopy!(pybuiltins.$k, pygetattr(pybuiltinsmodule, $(string(k)), pybuiltins.None))))
190+
else
191+
push!(INIT_CONSTS_CODE, :(pycopy!(pybuiltins.$k, pygetattr(pybuiltinsmodule, $(string(k))))))
192+
end
186193
end
187194

188195
@eval function init_consts()

0 commit comments

Comments
 (0)