Skip to content

Commit

Permalink
Merge branch 'master' into pa/pkgversion
Browse files Browse the repository at this point in the history
  • Loading branch information
palday authored Jan 10, 2024
2 parents c80a140 + 0a507df commit cb40924
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 76 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ changes in `julia`.

## Supported features

* `@compat public foo, bar` marks `foo` and `bar` as public in Julia 1.11+ and is a no-op in Julia 1.10 and earlier. ([#50105]) (since Compat 4.10.0)

* `sort` for `NTuple` and other iterables. ([#46104]) (since Compat 4.9.0)
* `@compat public foo, bar` marks `foo` and `bar` as public in Julia 1.11+ and is a no-op in Julia 1.10 and earlier. ([#50105]) (since Compat 3.47.0, 4.10.0)

* `redirect_stdio`, for simple stream redirection. ([#37978]) (since Compat 4.8.0)

Expand All @@ -84,10 +82,10 @@ changes in `julia`.

* `div`, `lcm`, `gcd`, `/`, `rem`, and `mod` will `promote` heterogenous `Dates.Period`s ([`@bdf9ead9`]). (since Compat 4.3.0)

* `stack` combines a collection of slices into one array ([#43334]). (since Compat 4.2.0)
* `stack` combines a collection of slices into one array ([#43334]). (since Compat 3.46.0, 4.2.0)

* `keepat!` removes the items at all the indices which are not given and returns
the modified source ([#36229], [#42351]). (since Compat 4.1.0)
the modified source ([#36229], [#42351]). (since Compat 3.44.0, 4.1.0)

* `@compat (; a, b) = (; c=1, b=2, a=3)` supports property descturing assignment syntax ([#39285]).

Expand Down
36 changes: 0 additions & 36 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -755,42 +755,6 @@ if VERSION < v"1.7.0-DEV.1187"
export redirect_stdio
end

# https://github.com/JuliaLang/julia/pull/46104
if VERSION < v"1.10.0-DEV.1404"
using Base: Ordering, Forward, ord, lt, tail, copymutable, DEFAULT_STABLE, IteratorSize, HasShape, IsInfinite
function Base.sort(v; kws...)
size = IteratorSize(v)
size == HasShape{0}() && throw(ArgumentError("$v cannot be sorted"))
size == IsInfinite() && throw(ArgumentError("infinite iterator $v cannot be sorted"))
sort!(copymutable(v); kws...)
end
Base.sort(::AbstractString; kws...) =
throw(ArgumentError("sort(::AbstractString) is not supported"))
Base.sort(::Tuple; kws...) =
throw(ArgumentError("sort(::Tuple) is only supported for NTuples"))

function Base.sort(x::NTuple{N}; lt::Function=isless, by::Function=identity,
rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) where N
o = ord(lt,by,rev,order)
if N > 9
v = sort!(copymutable(x), DEFAULT_STABLE, o)
tuple((v[i] for i in 1:N)...)
else
_sort(x, o)
end
end
_sort(x::Union{NTuple{0}, NTuple{1}}, o::Ordering) = x
function _sort(x::NTuple, o::Ordering)
a, b = Base.IteratorsMD.split(x, Val(length(x)>>1))
merge(_sort(a, o), _sort(b, o), o)
end
merge(x::NTuple, y::NTuple{0}, o::Ordering) = x
merge(x::NTuple{0}, y::NTuple, o::Ordering) = y
merge(x::NTuple{0}, y::NTuple{0}, o::Ordering) = x # Method ambiguity
merge(x::NTuple, y::NTuple, o::Ordering) =
(lt(o, y[1], x[1]) ? (y[1], merge(x, tail(y), o)...) : (x[1], merge(tail(x), y, o)...))
end

include("deprecated.jl")

end # module Compat
37 changes: 2 additions & 35 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ end
DivideError: integer division error
Stacktrace:.*
caused by: UndefVarError: `?__not_a_binding__`? not defined
caused by: UndefVarError: `?__not_a_binding__`? not defined( in `Main`)?
Stacktrace:.*
"""s, sprint(show, excs_with_bts))

Expand All @@ -210,7 +210,7 @@ end
ERROR: DivideError: integer division error
Stacktrace:.*
caused by: UndefVarError: `?__not_a_binding__`? not defined
caused by: UndefVarError: `?__not_a_binding__`? not defined( in `Main`)?
Stacktrace:.*
"""s, sprint(Base.display_error, excs_with_bts))

Expand Down Expand Up @@ -699,39 +699,6 @@ end
end
end

# https://github.com/JuliaLang/julia/pull/46104
@testset "sort(iterable)" begin
function tuple_sort_test(x)
@test issorted(sort(x))
length(x) > 9 && return # length > 9 uses a vector fallback
@test 0 == @allocated sort(x)
end
@testset "sort(::NTuple)" begin
@test sort((9,8,3,3,6,2,0,8)) == (0,2,3,3,6,8,8,9)
@test sort((9,8,3,3,6,2,0,8), by=x->x÷3) == (2,0,3,3,8,6,8,9)
for i in 1:40
tuple_sort_test(tuple(rand(i)...))
end
@test_throws ArgumentError sort((1,2,3.0))
end
@testset "sort!(iterable)" begin
gen = (x % 7 + 0.1x for x in 1:50)
@test sort(gen) == sort!(collect(gen))
gen = (x % 7 + 0.1y for x in 1:10, y in 1:5)
@test sort(gen; dims=1) == sort!(collect(gen); dims=1)
@test sort(gen; dims=2) == sort!(collect(gen); dims=2)

@test_throws ArgumentError("dimension out of range") sort(gen; dims=3)

@test_throws UndefKeywordError(:dims) sort(gen)
@test_throws UndefKeywordError(:dims) sort(collect(gen))
@test_throws UndefKeywordError(:dims) sort!(collect(gen))

@test_throws ArgumentError sort("string")
@test_throws ArgumentError("1 cannot be sorted") sort(1)
end
end

module Mod50105
using Compat
@compat public foo, var"#", baz
Expand Down

0 comments on commit cb40924

Please sign in to comment.