Skip to content

Commit bbd034d

Browse files
annzenkinamrknkoukojix2
authored
spec: Fix compatibility with Ruby 3.4.0 in ranges (#191)
[CI in the upstream](https://github.com/mrkn/pycall.rb/actions/runs/12501779028/job/34879787889) fails for the latest Ruby version 3.4: ``` 1) PyCall::PyObjectWrapper#[] when the given index is an Enumerable that is created by Range#step is expected to eq [2, 4, 6, 8] Failure/Error: expect(list[(nil..nil).step(-1)]).to eq(PyCall::List.new([*1..10].reverse)) ArgumentError: #step for non-numeric beginless ranges is meaningless # ./spec/pycall/pyobject_wrapper_spec.rb:164:in 'Range#step' # ./spec/pycall/pyobject_wrapper_spec.rb:164:in 'block (4 levels) in <module:PyCall>' ``` It looks like this happens due [to this change in the most recent Ruby version](https://github.com/ruby/ruby/blame/master/range.c#L524-L527) which doesn't allow to use "beginless" ranges anymore. This PR sets the range explicitly so we can avoid failing with an exception See also: * https://bugs.ruby-lang.org/issues/18368 * ruby/ruby#7444 --------- Co-authored-by: Kenta Murata <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: kojix2 <[email protected]>
1 parent 899fbf5 commit bbd034d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spec/pycall/pyobject_wrapper_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ module PyCall
161161
list = PyCall::List.new([*1..10])
162162
expect(list[(1..-1).step(2)]).to eq(PyCall::List.new([2, 4, 6, 8, 10]))
163163
expect(list[(1..-2).step(2)]).to eq(PyCall::List.new([2, 4, 6, 8]))
164-
expect(list[(nil..nil).step(-1)]).to eq(PyCall::List.new([*1..10].reverse))
165164
expect(list[(-1..0).step(-1)]).to eq(PyCall::List.new([*1..10].reverse))
165+
# In Ruby 3.4+, step for non-numeric beginless ranges raises ArgumentError
166+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.4.0')
167+
expect(list[(nil..nil).step(-1)]).to eq(PyCall::List.new([*1..10].reverse))
168+
end
166169
expect(list[(-1...0).step(-1)]).to eq(PyCall::List.new([*2..10].reverse))
167170
expect(list[(-2..2).step(-2)]).to eq(PyCall::List.new([9, 7, 5, 3]))
168171
expect(list[(-2...2).step(-2)]).to eq(PyCall::List.new([9, 7, 5]))

0 commit comments

Comments
 (0)