-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
undef
does not have parseable repr
#33204
Comments
undef
/UndefInitializer()
does not have parsable repr
undef
does not have parseable repr
Slightly separate from the issue of a parseable julia> fill(undef)
0-dimensional Array{UndefInitializer,0}:
array initializer with undefined values
julia> Array{Any, 0}(undef)
0-dimensional Array{Any,0}:
#undef It seem to me that something like julia> [undef undef undef undef]
1×4 Array{UndefInitializer,2}:
array initializer with undefined values … array initializer with undefined values would be much clearer as julia> [undef undef undef undef]
1×4 Array{UndefInitializer,2}:
undef undef undef undef |
I disagree. |
That seems fair enough, and we do get a "good" display in sensible use cases, e.g. julia> Matrix(undef, 1, 4)
1×4 Array{Any,2}:
#undef #undef #undef #undef Anyway, this was an aside :) The main issue is the second case here: # this seems fine
julia> UndefInitializer()
array initializer with undefined values
# expected `undef` or `UndefInitializer()`
julia> repr(UndefInitializer())
"array initializer with undefined values" |
What is the use case here, i.e. what are you trying to do where this is a problem? |
my main use-case of repr in general is to answer "how do I create a value like this?" |
seems like you tried to fill an array with undefined values and mistakenly used the undef array initializer. To me, the current printing prevented a bug. |
certainly open to suggestions on the 0-dim |
Should be easy to fix: just change show(io::IO, ::UndefInitializer) = print(io, "undef")
show(io::IO, ::MIME"text/plain", ::UndefInitializer) = print(io, "undef: array initializer with undefined values") This would keep the verbose interactive I would be in favor of this change. |
I would also be in favor of printing |
It seems needless, to me, not to have a "parseable" representation here (#30757) (in the sense
x == eval(Meta.parse(repr(x)))
).We sort of workaround this in a few places, by having
Base.undef_ref_str
julia/base/show.jl
Line 1848 in 90d481e
As far as I can tell, we could just change the current
show
method fromjulia/base/show.jl
Line 3 in 90d481e
to only be for the
text/plain
MIME type,e.g.
Since we have
julia/base/boot.jl
Lines 401 to 402 in 4111609
perhaps if we wanted more compact printing we could also define
The text was updated successfully, but these errors were encountered: