JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
44.98k stars 5.42k forks source link

length() no longer works with Iterators.Stateful in Julia 1.11rc1 #54953

Open s-fuerst opened 1 week ago

s-fuerst commented 1 week ago

In Julia 1.10, the following code works as expected:

julia> length(Iterators.Stateful([1,2,3]))
3

However, in Julia 1.11rc1, the same code fails with this error message:

MethodError: no method matching length(::Base.Iterators.Stateful{Vector{Int64}, Union{Nothing, Tuple{Int64, Int64}}})

This change in behavior appears to be unintended and breaks existing code that relies on being able to get the length of a Stateful iterator.

Steps to reproduce:

  1. Install Julia 1.11rc1
  2. Run the code: length(Iterators.Stateful([1,2,3]))

Expected behavior: Returns 3 Actual behavior: MethodError: no method matching length(::Base.Iterators.Stateful{Vector{Int64}, Union{Nothing, Tuple{Int64, Int64}}})

System information:

nsajko commented 1 week ago

This was a necessary change to do because the previous behavior was incorrect, see #47790.

EDIT: also, please use code blocks in your Markdown.

s-fuerst commented 1 week ago

For such a breaking change the minimum should be that this is mentioned in the documentation. But in my opinion such a breaking change should never happen without a deprecation warning for some time. This is a (in my opinion questionable) change in the API which can break packages like mine and not a "minor change" like the label on the PR #47790 claims.