-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Abbreviate show(io, ::Module)
#54347
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
base: master
Are you sure you want to change the base?
Conversation
For cases like ``` module A module B end end ``` , `A` is already visible in `Main` once defined. As a consequence, `B` can be accessed through `A.B` without having to go through `Main`. This adjusts the printing of `A.B`, so that this is reflected. This also makes cases like ``` module A export B module B end end ``` print like `B` and not `A.B` after `using A`, since `B` is already accessible from `Main`.
Failures are real - one consequence of this PR is that e.g.
It's long been convention though to prefix these with |
My usecase is consistency of module A
export B
module B
struct C end
end
end Users aren't generally expected to need julia> using .A
julia> println(IOContext(stdout, :module => Main), B.C())
Main.A.B.C()
julia> println(IOContext(stdout, :module => A), B.C())
Main.A.B.C()
julia> println(IOContext(stdout, :module => B), B.C())
C()
julia> println(IOContext(stdout, :module => Base), B.C())
Main.A.B.C()
julia> versioninfo()
Julia Version 1.11.0-alpha2
Commit 9dfd28ab751 (2024-03-18 20:35 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 24 × AMD Ryzen 9 7900X 12-Core Processor
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 24 virtual cores)
Environment:
JULIA_PKG_USE_CLI_GIT = true Ideally, these would be (per module context) printed as
but as you note, that runs into trouble with too much location specific printing. Personally, I'd prefer to print things globally the same, in a way that they are as short as possible while still being copy-pastable. That's what this PR attempts. Would it be better if this checks |
Instead of hardcoding `Main` to be more special, it's better to either retrieve a given module from an `IOContext`, or use the currently active module for printing.
I've adjusted the code to first try to retrieve a given context module from the given |
Failures are real - seems like I missed some earlier! I'll get to them tomorrow. |
f484651
to
d6ec22d
Compare
For cases like
,
A
is already visible inMain
once defined. As a consequence,B
can be accessed throughA.B
without having to go throughMain
. This adjusts the printing ofA.B
, so that this is reflected.This also makes cases like
have
f
printed likeB.f
and notA.B.f
afterusing A
, sinceB
is also already accessible inMain
.