diff --git a/README.md b/README.md index ad94f7f4..ea45bc06 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/PyCall.jl b/src/PyCall.jl index 37cd10c2..6e82b008 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 3db84b83..b9ef256e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -560,3 +560,5 @@ end @test_throws ErrorException @pywith IgnoreError(false) error() @test (@pywith IgnoreError(true) error(); true) end + +include("testmisc.jl") \ No newline at end of file diff --git a/test/testmisc.jl b/test/testmisc.jl new file mode 100644 index 00000000..82eb1d9e --- /dev/null +++ b/test/testmisc.jl @@ -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