Skip to content
Closed
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
15 changes: 14 additions & 1 deletion src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@

# convert Python args to Julia; overridden below for a FuncWrapper type
# that allows the user to specify the argument types.
julia_args(f, args) = convert(PyAny, args)
julia_args(f, args) =
[_julia_arg(_getindex(args, i, PyObject)) for i in 1:length(args)]
julia_kwarg(f, kw, arg) = convert(PyAny, arg)

# For mutating functions such as fill! to mutate Python objects,
# arguments have to be wrapped by an appropriate wrapper (e.g.,
# PyArray) rather than copying to a Julia object.
function _julia_arg(arg)
if haskey(PyCall.npy_api, :PyArray_Type) &&
pyisinstance(arg, PyCall.npy_api[:PyArray_Type])
return convert(PyArray, arg)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to move the code above inside convert(::Type{PyAny}, o::PyObject)?

else
return convert(PyAny, arg)
end
end

function _pyjlwrap_call(f, args_::PyPtr, kw_::PyPtr)
args = PyObject(args_) # don't need pyincref because of finally clause below
try
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ const PyInt = pyversion < v"3" ? Int : Clonglong
@test x == ["bar"]
end

py"""
def apply(f, *args):
f(*args)
return args
"""
@test py"apply"(fill!, zeros(3), 10)[1] == [10, 10, 10]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should have called it apply_inplace or sth to avoid confusion with Python 2 builtin apply.


@test roundtripeq(Dates.Date(2012,3,4))
@test roundtripeq(Dates.DateTime(2012,3,4, 7,8,9,11))
@test roundtripeq(Dates.Millisecond(typemax(Int32)))
Expand Down