From 436b3140e72b9f24d1e3e5595316867600bc1eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=AE=B6=E8=B1=AA?= Date: Tue, 26 Sep 2023 09:00:30 +0800 Subject: [PATCH] remove method of converting PyObject to Nothing --- src/conversions.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/conversions.jl b/src/conversions.jl index 0226f036..a6f09482 100644 --- a/src/conversions.jl +++ b/src/conversions.jl @@ -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) @@ -771,7 +772,7 @@ end macro return_not_None(ex) quote T = $(esc(ex)) - if T != Union{} + if T !== Union{} return T end end @@ -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