Skip to content

Commit a05f640

Browse files
author
Christopher Doris
committed
rename pynext to unsafe_pynext
1 parent ec76f01 commit a05f640

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

src/Py.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Base.eltype(::Type{Py}) = Py
260260
Base.IteratorSize(::Type{Py}) = Base.SizeUnknown()
261261

262262
function Base.iterate(x::Py, it::Py=pyiter(x))
263-
v = pynext(it)
263+
v = unsafe_pynext(it)
264264
if ispynull(v)
265265
pydel!(it)
266266
nothing

src/abstract/collection.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function _pyconvert_rule_iterable(ans::Vector{T0}, it::Py, ::Type{T1}) where {T0,T1}
44
@label again
5-
x_ = pynext(it)
5+
x_ = unsafe_pynext(it)
66
if ispynull(x_)
77
pydel!(it)
88
return pyconvert_return(ans)
@@ -28,7 +28,7 @@ end
2828

2929
function _pyconvert_rule_iterable(ans::Set{T0}, it::Py, ::Type{T1}) where {T0,T1}
3030
@label again
31-
x_ = pynext(it)
31+
x_ = unsafe_pynext(it)
3232
if ispynull(x_)
3333
pydel!(it)
3434
return pyconvert_return(ans)
@@ -54,7 +54,7 @@ end
5454

5555
function _pyconvert_rule_mapping(ans::Dict{K0,V0}, x::Py, it::Py, ::Type{K1}, ::Type{V1}) where {K0,V0,K1,V1}
5656
@label again
57-
k_ = pynext(it)
57+
k_ = unsafe_pynext(it)
5858
if ispynull(k_)
5959
pydel!(it)
6060
return pyconvert_return(ans)
@@ -127,21 +127,21 @@ end
127127

128128
function pyconvert_rule_iterable(::Type{R}, x::Py, ::Type{Pair{K0,V0}}=Utils._type_lb(R), ::Type{Pair{K1,V1}}=Utils._type_ub(R)) where {R<:Pair,K0,V0,K1,V1}
129129
it = pyiter(x)
130-
k_ = pynext(it)
130+
k_ = unsafe_pynext(it)
131131
if ispynull(k_)
132132
pydel!(it)
133133
pydel!(k_)
134134
return pyconvert_unconverted()
135135
end
136136
k = @pyconvert_and_del(K1, k_)
137-
v_ = pynext(it)
137+
v_ = unsafe_pynext(it)
138138
if ispynull(v_)
139139
pydel!(it)
140140
pydel!(v_)
141141
return pyconvert_unconverted()
142142
end
143143
v = @pyconvert_and_del(V1, v_)
144-
z_ = pynext(it)
144+
z_ = unsafe_pynext(it)
145145
pydel!(it)
146146
if ispynull(z_)
147147
pydel!(z_)

src/abstract/iter.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ Equivalent to `iter(x)` in Python.
66
pyiter(x) = pynew(errcheck(@autopy x C.PyObject_GetIter(getptr(x_))))
77
export pyiter
88

9-
pynext(x::Py) = pynew(errcheck_ambig(C.PyIter_Next(getptr(x))))
10-
export pyiter
9+
"""
10+
unsafe_pynext(x)
11+
12+
Return the next item in the iterator `x`. When there are no more items, return NULL.
13+
"""
14+
unsafe_pynext(x::Py) = pynew(errcheck_ambig(C.PyIter_Next(getptr(x))))

src/py_macro.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ function py_macro_lower(st, body, ans, ex; flavour=:expr)
595595
push!(body, :($i = $pyiter($y)))
596596
py_macro_del(body, y, ty)
597597
body2 = []
598-
push!(body2, :($v = $pynext($i)))
598+
push!(body2, :($v = $unsafe_pynext($i)))
599599
push!(body2, Expr(:if, :($ispynull($v)), Expr(:block, :($pydel!($v)), :(break))))
600600
py_macro_lower_assign(st, body2, ax, v)
601601
py_macro_del(body2, v, true)

src/pywrap/PyDict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pyconvert_rule_mapping(::Type{T}, x::Py, ::Type{PyDict{K,V}}=Utils._type_ub(T))
3333
Base.length(x::PyDict) = Int(pylen(x))
3434

3535
function Base.iterate(x::PyDict{K,V}, it::Py=pyiter(x)) where {K,V}
36-
k_ = pynext(it)
36+
k_ = unsafe_pynext(it)
3737
ispynull(k_) && return nothing
3838
v_ = pygetitem(x, k_)
3939
k = pyconvert_and_del(K, k_)
@@ -42,7 +42,7 @@ function Base.iterate(x::PyDict{K,V}, it::Py=pyiter(x)) where {K,V}
4242
end
4343

4444
function Base.iterate(x::Base.KeySet{K,PyDict{K,V}}, it::Py=pyiter(x.dict)) where {K,V}
45-
k_ = pynext(it)
45+
k_ = unsafe_pynext(it)
4646
ispynull(k_) && return nothing
4747
k = pyconvert_and_del(K, k_)
4848
return (k, it)

src/pywrap/PyIterable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Base.IteratorSize(::Type{PyIterable{T}}) where {T} = Base.SizeUnknown()
2020
Base.eltype(::Type{PyIterable{T}}) where {T} = T
2121

2222
function Base.iterate(x::PyIterable{T}, it::Py=pyiter(x)) where {T}
23-
y = pynext(it)
23+
y = unsafe_pynext(it)
2424
if ispynull(y)
2525
pydel!(it)
2626
return nothing

src/pywrap/PySet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Base.length(x::PySet) = Int(pylen(x))
3030
Base.isempty(x::PySet) = length(x) == 0
3131

3232
function Base.iterate(x::PySet{T}, it::Py=pyiter(x)) where {T}
33-
y = pynext(it)
33+
y = unsafe_pynext(it)
3434
if ispynull(y)
3535
pydel!(it)
3636
return nothing

test/abstract.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ end
213213
@test_throws PyException pyiter(pybuiltins.None)
214214
@test_throws PyException pyiter(pybuiltins.True)
215215
it = pyiter(pyrange(2))
216-
x = PythonCall.pynext(it)
216+
x = PythonCall.unsafe_pynext(it)
217217
@test !PythonCall.ispynull(x)
218218
@test pyeq(Bool, x, 0)
219-
x = PythonCall.pynext(it)
219+
x = PythonCall.unsafe_pynext(it)
220220
@test !PythonCall.ispynull(x)
221221
@test pyeq(Bool, x, 1)
222-
x = PythonCall.pynext(it)
222+
x = PythonCall.unsafe_pynext(it)
223223
@test PythonCall.ispynull(x)
224224
end
225225

0 commit comments

Comments
 (0)