Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PkgId repr #52795

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Fix PkgId repr #52795

merged 2 commits into from
Feb 8, 2024

Conversation

IanButterworth
Copy link
Member

Fixes #52793

% ./julia  --startup-file=no -E 'repr(Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise"))'
"Base.PkgId(UUID(\"295af30f-e4ad-537b-8983-00126c2a3abe\"), \"Revise\")"
julia> Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise")
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]

Although UUID should be Base.UUID otherwise this is only usable in Base.

Also interpolation seems to be using the wrong show method?

julia> pkgid = Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise")
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]

julia> "$pkgid"
"Base.PkgId(UUID(\"295af30f-e4ad-537b-8983-00126c2a3abe\"), \"Revise\")"

@stevengj
Copy link
Member

In Julia 1.10, interpolation is calling the expected show method:

julia> pkgid = Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise")
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]

julia> "$pkgid"
"Revise [295af30f-e4ad-537b-8983-00126c2a3abe]"

@IanButterworth
Copy link
Member Author

Indeed. This PR breaks that. I'm not sure how to achieve both a usable repr and the nice interpolation version

@stevengj
Copy link
Member

The missing qualification of Base.UUID is apparently due to the UUID show method:

julia> Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe")
UUID("295af30f-e4ad-537b-8983-00126c2a3abe")

which should probably be defined as:

show(io::IO, u::UUID) = print(io, UUID, "(\"", u, "\")")

so that it uses the show machinery for the type name.

@stevengj
Copy link
Member

stevengj commented Jan 10, 2024

I'm not sure how to achieve both a usable repr and the nice interpolation version

Interpolation calls print, which by default calls the 2-argument show. What do you want the interpolation to look like? Shouldn't it look like repr?

Normally the 3-arg show verbose/pretty form should only be used for things like REPL display (and explicit requests for text/plain output). If someone wants the display version in a string they should call repr("text/plain", pkgid).

@IanButterworth
Copy link
Member Author

IanButterworth commented Jan 12, 2024

What I think would make sense and be helpful would be

julia> pkgid
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]

julia> "$pkgid did something"
"Revise [295af30f-e4ad-537b-8983-00126c2a3abe] did something"

julia> "$(repr(pkgid))"
"Base.PkgId(UUID(\"295af30f-e4ad-537b-8983-00126c2a3abe\"), \"Revise\")"

julia> repr(pkgid))
"Base.PkgId(UUID(\"295af30f-e4ad-537b-8983-00126c2a3abe\"), \"Revise\")"

@stevengj
Copy link
Member

stevengj commented Jan 12, 2024

That's not the way string interpolation works with any other type of object AFAIK… I don't think it would be a good idea to make PkgId work differently.

If you want the 3-arg show version in string interpolation you do "$(repr("text/plain", pkgid)) did something"

jishnub pushed a commit that referenced this pull request Jan 13, 2024
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.
@IanButterworth IanButterworth marked this pull request as ready for review February 7, 2024 19:52
@IanButterworth IanButterworth added the merge me PR is reviewed. Merge when all tests are passing label Feb 7, 2024
@inkydragon
Copy link
Member

Only ":windows: build i686-w64-mingw32" failed in 4s.
So, LGTM?

@KristofferC KristofferC merged commit 4414599 into JuliaLang:master Feb 8, 2024
5 of 8 checks passed
@IanButterworth IanButterworth deleted the ib/pkgid_repr branch February 8, 2024 11:40
@inkydragon inkydragon removed the merge me PR is reviewed. Merge when all tests are passing label Feb 8, 2024
@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2024

I was just reading through the loading.jl file in detail, and it seems like this failed to update most of the places that I think would be expected, such as $modkey or $req_key or isprecompiled. Do we fix those or revert this for v1.11, or is that intended?

@KristofferC
Copy link
Member

Just fix them up I guess. This is still an improvement to make the show method follow the documentation of show and repr as in #52793 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repr of a PkgId isn't usable
5 participants