Skip to content

Commit 177baf8

Browse files
author
Jeffrey Lin
authored
fix show(::LinRange) (#35448)
Fixes #35437 This could be refined further (see comments in the PR), but it fixes the issue.
1 parent a400a24 commit 177baf8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

base/range.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,14 @@ range_start_stop_length(start::T, stop::T, len::Integer) where {T<:Integer} =
574574
# for all other types we fall back to a plain old LinRange
575575
_linspace(::Type{T}, start::Integer, stop::Integer, len::Integer) where T = LinRange{T}(start, stop, len)
576576

577-
function show(io::IO, r::LinRange)
578-
print(io, "range(")
577+
function show(io::IO, r::LinRange{T}) where {T}
578+
print(io, "LinRange{")
579+
show(io, T)
580+
print(io, "}(")
579581
show(io, first(r))
580-
print(io, ", stop=")
582+
print(io, ", ")
581583
show(io, last(r))
582-
print(io, ", length=")
584+
print(io, ", ")
583585
show(io, length(r))
584586
print(io, ')')
585587
end

test/ranges.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ end
11991199
@test repr("text/plain", range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
12001200
@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"
12011201
@test repr(range(1, stop=5, length=7)) == "1.0:0.6666666666666666:5.0"
1202-
@test repr(LinRange{Float64}(1,5,7)) == "range(1.0, stop=5.0, length=7)"
1202+
@test repr(LinRange{Float64}(1,5,7)) == "LinRange{Float64}(1.0, 5.0, 7)"
12031203
@test replrepr(0:100.) == "0.0:1.0:100.0"
12041204
# next is to test a very large range, which should be fast because print_range
12051205
# only examines spacing of the left and right edges of the range, sufficient

0 commit comments

Comments
 (0)