Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ cases where the Python return type is known can also improve
performance, both by eliminating the overhead of runtime type inference
and also by providing more type information to the Julia compiler.

* `pycall(function::PyObject, returntype::Type, args...)`. Call the given
Python `function` (typically looked up from a module) with the given
* `pycall(pyfunc::PyObject, returntype::Type, args...)`. Call the given
Python function `pyfunc` (typically looked up from a module) with the given
`args...` (of standard Julia types which are converted automatically to
the corresponding Python types if possible), converting the return value
to `returntype` (use a `returntype` of `PyObject` to return the unconverted
Python object reference, or of `PyAny` to request an automated conversion).
For convenience, a macro `@pycall` exists which automatically converts
`@pycall function(args...)::returntype` into
`pycall(function,returntype,args...)`.
* For convenience, a macro `@pycall` exists which automatically converts
`@pycall pyfunc(args...)::returntype` into
`pycall(pyfunc,returntype,args...)`.
* Another equivalent is `(pyfunc=>returntype)(args...)`. Alternatively you can define `pyfunc_ret = pyfunc=>returntype`, then call `pyfunc_ret(args...)` instead of `pycall(pyfunc,returntype,args...)`

* `pyimport(s)`: Import the Python module `s` (a string or symbol) and
return a pointer to it (a `PyObject`). Functions or other symbols
Expand Down
1 change: 1 addition & 0 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ pycall(o::Union{PyObject,PyPtr}, ::Type{PyAny}, args...; kwargs...) =
return convert(PyAny, _pycall(o, args...; kwargs...))

(o::PyObject)(args...; kws...) = pycall(o, PyAny, args...; kws...)
(ot::Pair{PyObject, <:TypeTuple})(args...; kws...) = pycall(ot[1], ot[2], args...; kws...)
PyAny(o::PyObject) = convert(PyAny, o)


Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,5 @@ end
@test_throws ErrorException @pywith IgnoreError(false) error()
@test (@pywith IgnoreError(true) error(); true)
end

include("testmisc.jl")
14 changes: 14 additions & 0 deletions test/testmisc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Compat.Test, PyCall

@testset "pair call syntax" begin
pylist = pybuiltin("list")
listpyo = pylist=>PyObject
listpytpl = pylist=>Tuple{Vararg{Float64}}
listpyvec = pylist=>Vector{Float64}
listpyany = pylist=>PyAny
@test typeof(listpyo(1.0:10.0)) == PyObject
@test listpytpl(1.0:10.0) isa Tuple{Vararg{Float64}}
@test typeof(listpytpl(1.0:10.0)) == NTuple{10, Float64}
@test typeof(listpyvec(1.0:10.0)) == Vector{Float64}
@test typeof(listpyany(1.0:10.0)) == Vector{Float64}
end