Skip to content

Commit 6dc0da4

Browse files
authored
show UUID as Base.UUID(...) when not imported (#52881)
Fixes the problem identified in #52795 (comment) thanks to @IanButterworth — currently, a `UUID` displays as: ```jl julia> Base.UUID("30b93cbd-6b28-44ea-8d3f-42a2b647d023") UUID("30b93cbd-6b28-44ea-8d3f-42a2b647d023") ``` even if the `UUID` symbol has not been imported. It should display as a qualified name `Base.UUID` unless `UUID` is imported (e.g. by doing `using UUIDs`). That is, after this PR you will get ```jl julia> Base.UUID("30b93cbd-6b28-44ea-8d3f-42a2b647d023") Base.UUID("30b93cbd-6b28-44ea-8d3f-42a2b647d023") ``` This is a tiny patch that just uses the standard type-printing machinery to decide how to display the `UUID` type name.
1 parent e3a64e8 commit 6dc0da4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/uuid.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let groupings = [36:-1:25; 23:-1:20; 18:-1:15; 13:-1:10; 8:-1:1]
101101
end
102102

103103
print(io::IO, u::UUID) = print(io, string(u))
104-
show(io::IO, u::UUID) = print(io, "UUID(\"", u, "\")")
104+
show(io::IO, u::UUID) = print(io, UUID, "(\"", u, "\")")
105105

106106
isless(a::UUID, b::UUID) = isless(a.value, b.value)
107107

test/misc.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,11 @@ end
13001300
@test sort([a, b]) == [b, a]
13011301
end
13021302

1303+
@testset "UUID display" begin
1304+
a = Base.UUID("dbd321ed-e87e-4f33-9511-65b7d01cdd55")
1305+
@test repr(a) == "$(Base.UUID)(\"dbd321ed-e87e-4f33-9511-65b7d01cdd55\")"
1306+
end
1307+
13031308
@testset "Libc.rand" begin
13041309
low, high = extrema(Libc.rand(Float64) for i=1:10^4)
13051310
# these fail with probability 2^(-10^4) ≈ 5e-3011

0 commit comments

Comments
 (0)