Skip to content

Commit 18459ed

Browse files
author
Christopher Doris
committed
wrappers no longer assume they own their object, and do not define pydel
1 parent c43810f commit 18459ed

File tree

6 files changed

+6
-13
lines changed

6 files changed

+6
-13
lines changed

src/pywrap/PyDict.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If `x` is not a Python object, it is converted to one using `pydict`.
77
"""
88
struct PyDict{K,V} <: AbstractDict{K,V}
99
py :: Py
10-
PyDict{K,V}(x=pydict()) where {K,V} = new{K,V}(ispy(x) ? pynew(Py(x)) : pydict(x))
10+
PyDict{K,V}(x=pydict()) where {K,V} = new{K,V}(ispy(x) ? Py(x) : pydict(x))
1111
end
1212
export PyDict
1313

@@ -16,7 +16,6 @@ PyDict(x=pydict()) = PyDict{Py,Py}(x)
1616

1717
ispy(::PyDict) = true
1818
Py(x::PyDict) = x.py
19-
pydel!(x::PyDict) = pydel!(x.py)
2019

2120
pyconvert_rule_mapping(::Type{T}, x::Py, ::Type{PyDict{K,V}}=Utils._type_ub(T)) where {T<:PyDict,K,V} =
2221
if PyDict{Py,Py} <: T

src/pywrap/PyIO.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,19 @@ mutable struct PyIO <: IO
3939
ibuflen > 0 || error("ibuflen must be positive")
4040
obuflen = convert(Int, obuflen)
4141
obuflen > 0 || error("obuflen must be positive")
42-
new(pynew(Py(x)), own, text, false, ibuflen, UInt8[], obuflen, UInt8[])
42+
new(Py(x), own, text, false, ibuflen, UInt8[], obuflen, UInt8[])
4343
end
4444
end
4545
export PyIO
4646

4747
pyio_finalize!(io::PyIO) = begin
4848
C.CTX.is_initialized || return
4949
io.own ? close(io) : flush(io)
50-
pydel!(io.py)
5150
return
5251
end
5352

5453
ispy(io::PyIO) = true
5554
Py(io::PyIO) = io.py
56-
pydel!(io::PyIO) = (finalize(io); nothing)
5755

5856
pyconvert_rule_io(::Type{PyIO}, x::Py) = pyconvert_return(PyIO(x))
5957

src/pywrap/PyIterable.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ This object iterates over iterable Python object `x`, yielding values of type `T
55
"""
66
struct PyIterable{T}
77
py :: Py
8-
PyIterable{T}(x) where {T} = new{T}(pynew(Py(x)))
8+
PyIterable{T}(x) where {T} = new{T}(Py(x))
99
end
1010
export PyIterable
1111

1212
PyIterable(x) = PyIterable{Py}(x)
1313

1414
ispy(x::PyIterable) = true
1515
Py(x::PyIterable) = x.py
16-
pydel!(x::PyIterable) = pydel!(x.py)
1716

1817
Base.IteratorSize(::Type{PyIterable{T}}) where {T} = Base.SizeUnknown()
1918
Base.eltype(::Type{PyIterable{T}}) where {T} = T

src/pywrap/PyList.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ If `x` is not a Python object, it is converted to one using `pylist`.
77
"""
88
struct PyList{T} <: AbstractVector{T}
99
py :: Py
10-
PyList{T}(x=pylist()) where {T} = new{T}(ispy(x) ? pynew(Py(x)) : pylist(x))
10+
PyList{T}(x=pylist()) where {T} = new{T}(ispy(x) ? Py(x) : pylist(x))
1111
end
1212
export PyList
1313

1414
PyList(x=pylist()) = PyList{Py}(x)
1515

1616
ispy(::PyList) = true
1717
Py(x::PyList) = x.py
18-
pydel!(x::PyList) = pydel!(x.py)
1918

2019
pyconvert_rule_sequence(::Type{T}, x::Py, ::Type{PyList{V}}=Utils._type_ub(T)) where {T<:PyList,V} =
2120
if PyList{Py} <: T

src/pywrap/PyPandasDataFrame.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ struct PyPandasDataFrame <: PyTable
1616
columnnames::Function # Py -> Symbol
1717
columntypes::Function # Symbol -> Union{Type,Nothing}
1818
function PyPandasDataFrame(x; indexname::Union{Symbol,Nothing}=nothing, columnnames::Function=x->Symbol(x), columntypes::Function=x->nothing)
19-
new(pynew(Py(x)), indexname, columnnames, columntypes)
19+
new(Py(x), indexname, columnnames, columntypes)
2020
end
2121
end
2222
export PyPandasDataFrame
2323

2424
ispy(x::PyPandasDataFrame) = true
2525
Py(x::PyPandasDataFrame) = x.py
26-
pydel!(x::PyPandasDataFrame) = pydel!(x.py)
2726

2827
pyconvert_rule_pandasdataframe(::Type{PyPandasDataFrame}, x::Py) = pyconvert_return(PyPandasDataFrame(x))
2928

src/pywrap/PySet.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ If `x` is not a Python object, it is converted to one using `pyset`.
77
"""
88
struct PySet{T} <: AbstractSet{T}
99
py :: Py
10-
PySet{T}(x=pyset()) where {T} = new{T}(ispy(x) ? pynew(Py(x)) : pyset(x))
10+
PySet{T}(x=pyset()) where {T} = new{T}(ispy(x) ? Py(x) : pyset(x))
1111
end
1212
export PySet
1313

1414
PySet(x=pyset()) = PySet{Py}(x)
1515

1616
ispy(::PySet) = true
1717
Py(x::PySet) = x.py
18-
pydel!(x::PySet) = pydel!(x.py)
1918

2019
pyconvert_rule_set(::Type{T}, x::Py, ::Type{PySet{V}}=Utils._type_ub(T)) where {T<:PySet,V} =
2120
if PySet{Py} <: T

0 commit comments

Comments
 (0)