-
-
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
errorshow: simplify printing of keyword argument types using a new macro format #49959
Conversation
82937a6
to
f244ad9
Compare
If it is exported then the |
I didn't export it because I considered it as an internal implementation detail that keyword arguments are represented as |
If that implementation changes then |
base/show.jl
Outdated
print(io, "}") | ||
return | ||
end | ||
elseif get(io, :simplify_kwstype, false) && kwsnt !== nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I enabled the printing with the @Kwargs
-macro syntax only within stack trace view. Please let me know if you think it is more reasonable to enable the printing in the other situations.
The main reasoning behind the current choice is that Base.Pairs
is a general data structure and its usage is not restricted to represent keyword arguments.
8aa7e1e
to
5e6baf9
Compare
I'd argue that 6 👍 means this PR is preferable. I'm planning to merge this PR tomorrow if there are no objections. |
…ew macro format In Julia, keyword arguments are represented as `Base.Pairs` objects. However, the object type often appears unnecessarily complex, especially when printed in a stack trace. This commit aims to simplify the printing of stack traces that involve keyword method calls, while still allowing us to reconstruct the actual method signature types from the printed signature types. The approach is similar to #49117: this commit introduces a new macro called `Base.@Kwargs`. It follows the same syntax as `@NamedTuple` and returns a `Base.Pairs` type that is used for keyword method calls. We use this syntax when printing keyword argument types. Here's an example of a stack trace: ```diff diff --git a/b.jl b/a.jl index 91dd6f0464..b804ae4be5 100644 --- a/b.jl +++ b/a.jl @@ -22,12 +22,11 @@ Stacktrace: @ Base ./reduce.jl:44 [inlined] [6] mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String; init::Int64) @ Base ./reduce.jl:175 [inlined] - [7] mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::Base.Pairs{…}) + [7] mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:307 [inlined] - [8] sum(f::typeof(identity), a::String; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, @NamedTuple{init::Int64}}) + [8] sum(f::typeof(identity), a::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:535 [inlined] - [9] sum(a::String; kw::Base.Pairs{Symbol, Int64, Tuple{Symbol}, @NamedTuple{init::Int64}}) + [9] sum(a::String; kw::Base.@kwargs{init::Int64}) @ Base ./reduce.jl:564 [inlined] [10] top-level scope ``` Feel free to share any comments or suggestions. If this idea seems acceptable, I will add test cases and also address any broken test cases.
… stack trace view And add tests.
Since keyword pairs can appear within positional arguments, it can be confusing if we print the same type with different representations.
In Julia, keyword arguments are represented as
Base.Pairs
objects. However, the object type often appears unnecessarily complex, especially when printed in a stack trace.This commit aims to simplify the printing of stack traces that involve keyword method calls, while still allowing us to reconstruct the actual method signature types from the printed signature types.
The approach is similar to #49117: this commit introduces a new macro called
Base.@Kwargs
. It follows the same syntax as@NamedTuple
and returns aBase.Pairs
type that is used for keyword method calls. We use this syntax when printing keyword argument types.Here's an example of a stack trace for
sum("julia"; init=1)
:Feel free to share any comments or suggestions. If this idea seems acceptable, I will add test cases and also address any broken test cases.