Skip to content

Commit

Permalink
fix show(::LinRange) (#35448)
Browse files Browse the repository at this point in the history
Fixes #35437

This could be refined further (see comments in the PR), but it fixes the issue.
  • Loading branch information
anaveragehuman committed Jan 25, 2022
1 parent a400a24 commit 177baf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,14 @@ range_start_stop_length(start::T, stop::T, len::Integer) where {T<:Integer} =
# for all other types we fall back to a plain old LinRange
_linspace(::Type{T}, start::Integer, stop::Integer, len::Integer) where T = LinRange{T}(start, stop, len)

function show(io::IO, r::LinRange)
print(io, "range(")
function show(io::IO, r::LinRange{T}) where {T}
print(io, "LinRange{")
show(io, T)
print(io, "}(")
show(io, first(r))
print(io, ", stop=")
print(io, ", ")
show(io, last(r))
print(io, ", length=")
print(io, ", ")
show(io, length(r))
print(io, ')')
end
Expand Down
2 changes: 1 addition & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ end
@test repr("text/plain", range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr("text/plain", LinRange{Float64}(1,5,7)) == "7-element LinRange{Float64, Int$nb}:\n 1.0,1.66667,2.33333,3.0,3.66667,4.33333,5.0"
@test repr(range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
@test repr(LinRange{Float64}(1,5,7)) == "range(1.0, stop=5.0, length=7)"
@test repr(LinRange{Float64}(1,5,7)) == "LinRange{Float64}(1.0, 5.0, 7)"
@test replrepr(0:100.) == "0.0:1.0:100.0"
# next is to test a very large range, which should be fast because print_range
# only examines spacing of the left and right edges of the range, sufficient
Expand Down

0 comments on commit 177baf8

Please sign in to comment.