Skip to content

Commit 2adad5c

Browse files
author
Christopher Doris
committed
conversion to pywrapper now has eltype Any
1 parent 2d21824 commit 2adad5c

File tree

6 files changed

+20
-34
lines changed

6 files changed

+20
-34
lines changed

docs/src/releasenotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Release Notes
22

33
## Unreleased
4+
* Conversion to wrapper types `PyList`, `PySet`, `PyDict` or `PyIterable` now default to
5+
having element type `Any` instead of `Py`.
46
* The `__repr__` method of wrapped Julia objects now uses the 3-arg show method for nicer
57
(richer and truncated) display at the Python REPL.
68
* Bug fixes.

src/pywrap/PyDict.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@ PyDict(x=pydict()) = PyDict{Py,Py}(x)
1717
ispy(::PyDict) = true
1818
Py(x::PyDict) = x.py
1919

20-
pyconvert_rule_mapping(::Type{T}, x::Py, ::Type{PyDict{K,V}}=Utils._type_ub(T)) where {T<:PyDict,K,V} =
21-
if PyDict{Py,Py} <: T
22-
pyconvert_return(PyDict{Py,Py}(x))
23-
elseif PyDict{K,Py} <: T
24-
pyconvert_return(PyDict{K,Py}(x))
25-
elseif PyDict{Py,V} <: T
26-
pyconvert_return(PyDict{Py,V}(x))
27-
else
28-
pyconvert_return(PyDict{K,V}(x))
29-
end
20+
function pyconvert_rule_mapping(::Type{T}, x::Py, ::Type{T1}=Utils._type_ub(T)) where {T<:PyDict,T1}
21+
pyconvert_return(T1(x))
22+
end
3023

3124
Base.length(x::PyDict) = Int(pylen(x))
3225

src/pywrap/PyIterable.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ function Base.iterate(x::PyIterable{T}, it::Py=pyiter(x)) where {T}
2727
end
2828
end
2929

30-
pyconvert_rule_iterable(::Type{T}, x::Py, ::Type{PyIterable{V}}=Utils._type_ub(T)) where {T<:PyIterable,V} =
31-
if PyIterable{Py} <: T
32-
pyconvert_return(PyIterable{Py}(x))
33-
else
34-
pyconvert_return(PyIterable{V}(x))
35-
end
30+
function pyconvert_rule_iterable(::Type{T}, x::Py, ::Type{T1}=Utils._type_ub(T)) where {T<:PyIterable,T1}
31+
pyconvert_return(T1(x))
32+
end

src/pywrap/PyList.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ PyList(x=pylist()) = PyList{Py}(x)
1616
ispy(::PyList) = true
1717
Py(x::PyList) = x.py
1818

19-
pyconvert_rule_sequence(::Type{T}, x::Py, ::Type{PyList{V}}=Utils._type_ub(T)) where {T<:PyList,V} =
20-
if PyList{Py} <: T
21-
pyconvert_return(PyList{Py}(x))
22-
else
23-
pyconvert_return(PyList{V}(x))
24-
end
19+
function pyconvert_rule_sequence(::Type{T}, x::Py, ::Type{T1}=Utils._type_ub(T)) where {T<:PyList,T1}
20+
pyconvert_return(T1(x))
21+
end
2522

2623
Base.length(x::PyList) = Int(pylen(x))
2724

src/pywrap/PySet.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ PySet(x=pyset()) = PySet{Py}(x)
1616
ispy(::PySet) = true
1717
Py(x::PySet) = x.py
1818

19-
pyconvert_rule_set(::Type{T}, x::Py, ::Type{PySet{V}}=Utils._type_ub(T)) where {T<:PySet,V} =
20-
if PySet{Py} <: T
21-
pyconvert_return(PySet{Py}(x))
22-
else
23-
pyconvert_return(PySet{V}(x))
24-
end
19+
function pyconvert_rule_set(::Type{T}, x::Py, ::Type{T1}=Utils._type_ub(T)) where {T<:PySet,T1}
20+
pyconvert_return(T1(x))
21+
end
2522

2623
Base.length(x::PySet) = Int(pylen(x))
2724

test/convert.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ end
171171

172172
@testitem "mapping → PyDict" begin
173173
x1 = pyconvert(PyDict, pydict([1=>11, 2=>22, 3=>33]))
174-
@test x1 isa PyDict{Py,Py}
175-
@test isequal(x1, Dict([Py(1)=>Py(11), Py(2)=>Py(22), Py(3)=>Py(33)]))
174+
@test x1 isa PyDict{Any,Any}
175+
@test isequal(x1, Dict([1=>11, 2=>22, 3=>33]))
176176
x2 = pyconvert(PyDict{Int,Int}, pydict([1=>11, 2=>22, 3=>33]))
177177
@test x2 isa PyDict{Int,Int}
178178
@test x2 == Dict(1=>11, 2=>22, 3=>33)
@@ -189,17 +189,17 @@ end
189189

190190
@testitem "sequence → PyList" begin
191191
x1 = pyconvert(PyList, pylist([1, 2, 3]))
192-
@test x1 isa PyList{Py}
193-
@test isequal(x1, [Py(1), Py(2), Py(3)])
192+
@test x1 isa PyList{Any}
193+
@test isequal(x1, [1, 2, 3])
194194
x2 = pyconvert(PyList{Int}, pylist([1, 2, 3]))
195195
@test x2 isa PyList{Int}
196196
@test x2 == [1, 2, 3]
197197
end
198198

199199
@testitem "set → PySet" begin
200200
x1 = pyconvert(PySet, pyset([1, 2, 3]))
201-
@test x1 isa PySet{Py}
202-
@test isequal(x1, Set([Py(1), Py(2), Py(3)]))
201+
@test x1 isa PySet{Any}
202+
@test isequal(x1, Set([1, 2, 3]))
203203
x2 = pyconvert(PySet{Int}, pyset([1, 2, 3]))
204204
@test x2 isa PySet{Int}
205205
@test x2 == Set([1, 2, 3])

0 commit comments

Comments
 (0)