Make copymutable public and add clarification to some docstrings#51939
Make copymutable public and add clarification to some docstrings#51939LilithHafner wants to merge 8 commits intomasterfrom
copymutable public and add clarification to some docstrings#51939Conversation
copymutable public and add clarification to some docstrings
|
The
I think the meaning of "mutable copy" here should be clarified somewhat. I gather that it basically means that the returned value must compare equal to the original (thus "copy") and the returned value must be mutable. |
|
Would it make sense to also include |
|
It would make sense to use mark
No. I'm explicitly marking it as public. Please check the diff. |
Sorry for the noise, yes PR and description matches (my intention was to alert to syncing, and it's good to know you're NOT exporting, and things match). I saw you editing "base/exports.jl" and missed seeing "public", so I assumed. It would be helpful to have separate file for that base/public.jl, which could import base/exports.jl. [You were editing line 1117 and public not visible until I expand/scroll up to line 1075, and it's not marked red as other keywords...] |
Agreed, though I would have Base.jl include both exports.jl and public.jl. Care to make a PR? |
|
@nsajko is it more clear now? |
|
Just some minor comments:
julia> s = Set([1,2,3]);
julia> s2 = Base.copymutable(s);
julia> typeof(s2)
Set{Int64}
julia> s === s2
false
|
base/sort.jl
Outdated
| Uses `Base.copymutable` to support immutable collections and iterables. | ||
| By default, `sort` copies its input with [`Base.copymutable`](@ref) before sorting, but some types have | ||
| specialized versions of `sort`, such as `NTuples` (`sort(::NTuple)` returns an `NTuple`) and | ||
| `Dict` (`sort(::Dict)` produces a new sorted dictionary data structure). |
There was a problem hiding this comment.
Maybe I don't have a recent-enough julia version installed, but sort(::Dict) for me produces a vector of Pair and not a sorted dictionary, do you confirm this changed?
There was a problem hiding this comment.
Related question, does sort(::Dict) returning a vector works thanks to the fact that copymutable is not yet specialized for Dict? Would implementing copymutable(d::Dict) = copy(d) break this? Would it make sense to support sort(Set(1)), and does it currently fail only because copymutable is used (instead of collect) for Set?
There was a problem hiding this comment.
In other words, while copymutable seems fine for arrays, I wonder whether collect wouldn't be better than copymutable for other iterables. As copymutable for arrays is just a thin wrapper atop similar, mentioning "similar for arrays and collect for iterable" might be simpler than introducing another copymutable concept.
There was a problem hiding this comment.
Haha, it's piracy by OrderedCollections that allows sort(::Dict) to work. OrderedCollections just gets loaded as a transitive dependency in my startup.jl file so I didn't realize. Also the pirated sort(::Dict) method is deprecated.
I don't like sort(::Dict) returning a vector of pairs, that is rarely what the user wants and it precludes the possibility of creating a better data structure instead.
| Base.step | ||
| Base.collect(::Any) | ||
| Base.collect(::Type, ::Any) | ||
| Base.copymutable(::Any) |
There was a problem hiding this comment.
I'm hesitant to make copymutable public now, at least as long as it's not implemented for AbstractDict.
|
Closing because #52098 makes the changes here obsolete. |
Fixes #51932