Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce method invalidations and latency by remove method of converting PyObject to nothing #1055

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/conversions.jl
Expand Up @@ -61,7 +61,8 @@ convert(::Type{T}, po::PyObject) where {T<:Real} =
convert(::Type{T}, po::PyObject) where T<:Complex =
T(@pycheck ccall(@pysym(:PyComplex_AsCComplex), Complex{Cdouble}, (PyPtr,), po))

convert(::Type{Nothing}, po::PyObject) = nothing
# TODO: This method defination causes method invalidations and latency in Julia 1.9.3, https://github.com/JuliaLang/julia/issues/51389
# convert(::Type{Nothing}, po::PyObject) = nothing

function Base.float(o::PyObject)
a = PyAny(o)
Expand Down Expand Up @@ -771,7 +772,7 @@ end
macro return_not_None(ex)
quote
T = $(esc(ex))
if T != Union{}
if T !== Union{}
return T
end
end
Expand Down Expand Up @@ -829,9 +830,13 @@ function convert(::Type{PyAny}, o::PyObject)
end
try
T = pytype_query(o)
if T == PyObject && is_pyjlwrap(o)
if T === PyObject && is_pyjlwrap(o)
return unsafe_pyjlwrap_to_objref(o)
end
if T === Nothing
return nothing
end

convert(T, o)
catch
pyerr_clear() # just in case
Expand Down