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

Change keyword arguments back to regular NamedTuples #25711

Closed
wants to merge 2 commits into from

Conversation

ararslan
Copy link
Member

Ref discussion in #25675. This reverts "undo breaking change to kwargs iteration order" (#25290) and makes keyword arguments regular ol' NamedTuples again. This is breaking, since NamedTuples iterate values rather than pairs (which motivated #25290) and so iteration of keyword arguments will be broken. Users who want the (name, value) iteration will need to use pairs.

@ararslan ararslan added kind:breaking This change will break code keyword arguments f(x; keyword=arguments) labels Jan 23, 2018
NEWS.md Outdated
@@ -196,6 +196,11 @@ Breaking changes

This section lists changes that do not have deprecation warnings.

* Keyword arguments are now `NamedTuple`s rather than `Iterators.IndexValue`s. This
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't mention IndexValue since that type isn't public.

@@ -164,7 +164,7 @@ function showerror(io::IO, ex::MethodError)
ft = typeof(f)
name = ft.name.mt.name
f_is_function = false
kwargs = ()
kwargs = NamedTuple()
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to change the line below that was changed by #25658.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Does it look right now?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file in the revert is wrong. We want kwargs to be a non-specialized container so that we don't compile a new copy of show_method_candidates.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't it already that way though? IndexValue is also specialized.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying I necessarily managed to catch all of this regression before. In v0.6, we copied it to a Vector{Any}. That's not strictly necessary though, as long we don't pass this as an argument to something that'll cause code-generation-specialization of our error-printing code.

Revert "undo breaking change to kwargs iteration order" (#25290)
This reverts commit b90274e.
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 24, 2018

While I don't think we should ever use NT for this, if we're going to change the iteration protocol, we should at least do it with a proper deprecation (e.g. copy the IndexValue code to a KeywordsArgs type, then implement the desired behavior and deprecations on it).

@JeffBezanson
Copy link
Sponsor Member

Agreed --- if we want to change this we should do a proper deprecation.

@JeffBezanson JeffBezanson added the status:triage This should be discussed on a triage call label Jan 24, 2018
@JeffBezanson
Copy link
Sponsor Member

From triage: we should rename IndexValue to Pairs, and print it as e.g. pairs((a=1, b=2)) to make it clearer. Then we can keep iterating kwargs as pairs.

@Keno Keno removed the status:triage This should be discussed on a triage call label Jan 25, 2018
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 25, 2018

and print it as

That too, but I think the main request was for printing the type more concisely. Currently the default show method likes to print the full type name of the container, but in this case, most of the information there isn't useful.

@vtjnash vtjnash closed this Jan 25, 2018
@ararslan ararslan deleted the aa/rip-the-bandaid branch January 25, 2018 22:21
Keno added a commit that referenced this pull request Jan 26, 2018
As discussed in #25711

Before:
```
julia> f(;kwargs...) = kwargs
f (generic function with 1 method)

julia> f(;a = 1, b = 2)
Base.Iterators.IndexValue{Symbol,Int64,Tuple{Symbol,Symbol},NamedTuple{(:a, :b),Tuple{Int64,Int64}}} with 2 entries:
  :a => 1
  :b => 2
```

After:
```
julia> f(;a = 1, b = 2)
pairs((a = 1, b = 2)) with 2 entries:
  :a => 1
  :b => 2
```
@rfourquet
Copy link
Member

WIth Pairs, we can't access the fields of the named tuple directly... Is it clear that its more generally useful to iterate over kwargs (with Pairs wrapping), than to access 1 kwarg as a named tuple field access (this PR)?

@Keno
Copy link
Member

Keno commented Jan 27, 2018

Why not both (we could define getproperty for the wrapper to forward to the NT when wrapping one)?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 27, 2018

named tuple field access

named tuples definitely came after field access, and have no special claim to the syntax (other than currently existing, while it has not yet been defined for Pairs)

Keno added a commit that referenced this pull request Feb 1, 2018
As discussed in #25711

Before:
```
julia> f(;kwargs...) = kwargs
f (generic function with 1 method)

julia> f(;a = 1, b = 2)
Base.Iterators.IndexValue{Symbol,Int64,Tuple{Symbol,Symbol},NamedTuple{(:a, :b),Tuple{Int64,Int64}}} with 2 entries:
  :a => 1
  :b => 2
```

After:
```
julia> f(;a = 1, b = 2)
pairs((a = 1, b = 2)) with 2 entries:
  :a => 1
  :b => 2
```
Keno added a commit that referenced this pull request Feb 1, 2018
As discussed in #25711

Before:
```
julia> f(;kwargs...) = kwargs
f (generic function with 1 method)

julia> f(;a = 1, b = 2)
Base.Iterators.IndexValue{Symbol,Int64,Tuple{Symbol,Symbol},NamedTuple{(:a, :b),Tuple{Int64,Int64}}} with 2 entries:
  :a => 1
  :b => 2
```

After:
```
julia> f(;a = 1, b = 2)
pairs((a = 1, b = 2)) with 2 entries:
  :a => 1
  :b => 2
```
JeffBezanson pushed a commit that referenced this pull request Feb 2, 2018
As discussed in #25711

Before:
```
julia> f(;kwargs...) = kwargs
f (generic function with 1 method)

julia> f(;a = 1, b = 2)
Base.Iterators.IndexValue{Symbol,Int64,Tuple{Symbol,Symbol},NamedTuple{(:a, :b),Tuple{Int64,Int64}}} with 2 entries:
  :a => 1
  :b => 2
```

After:
```
julia> f(;a = 1, b = 2)
pairs((a = 1, b = 2)) with 2 entries:
  :a => 1
  :b => 2
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keyword arguments f(x; keyword=arguments) kind:breaking This change will break code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants