Skip to content

Commit

Permalink
Doesn't make sense to have reverse for dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokazama committed Sep 25, 2022
1 parent d127a79 commit e6f5797
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
9 changes: 2 additions & 7 deletions src/PropertyDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module PropertyDicts

export PropertyDict

@static if !hasmethod(reverse, Tuple{NamedTuple})
Base.reverse(nt::NamedTuple) = NamedTuple{reverse(keys(nt))}(reverse(values(nt)))
end
@static if !hasmethod(mergewith, Tuple{Any,NamedTuple,NamedTuple})
function Base.mergewith(combine, a::NamedTuple{an}, b::NamedTuple{bn}) where {an, bn}
names = Base.merge_names(an, bn)
Expand Down Expand Up @@ -103,9 +100,9 @@ Base.keytype(@nospecialize T::Type{<:PropertyDict{String}}) = String
Base.keytype(@nospecialize T::Type{<:PropertyDict{Symbol}}) = Symbol

_tokey(@nospecialize(pd::PropertyDict{String}), k::AbstractString) = k
_tokey(@nospecialize(pd::PropertyDict{String}), k) = String(k)
_tokey(@nospecialize(pd::PropertyDict{String}), k::Symbol) = String(k)
_tokey(@nospecialize(pd::PropertyDict{Symbol}), k::Symbol) = k
_tokey(@nospecialize(pd::PropertyDict{Symbol}), k) = Symbol(k)
_tokey(@nospecialize(pd::PropertyDict{Symbol}), k::AbstractString) = Symbol(k)

Base.pop!(pd::PropertyDict, k) = pop!(getfield(pd, :d), _tokey(pd, k))
Base.pop!(pd::PropertyDict, k, d) = pop!(getfield(pd, :d), _tokey(pd, k), d)
Expand Down Expand Up @@ -151,8 +148,6 @@ Base.@propagate_inbounds function Base.setindex!(pd::PropertyDict, v, k)
setindex!(getfield(pd, :d), v, _tokey(pd, k))
end

Base.reverse(pd::PropertyDict) = PropertyDict(reverse(getfield(pd, :d)))

@inline function Base.iterate(pd::NamedProperties)
if isempty(pd)
nothing
Expand Down
6 changes: 0 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ using Test
@test isa(PropertyDict{String,Int}(PropertyDict{String,Int}(Dict("foo" => 1, "bar" => 2))), PropertyDict{String,Int,Dict{String,Int}})
end

# PropertyDict{K,V}(arg, args...) where {K,V} = PropertyDict{K,V}(Dict(arg, args...))
# PropertyDict{String}(@nospecialize(pd::PropertyDict{String})) = pd


d = Dict("foo"=>1, :bar=>2)
_keys = collect(keys(d))
pd = PropertyDict(d)
Expand Down Expand Up @@ -109,8 +105,6 @@ end
@test Base.IteratorEltype(pd) == Base.IteratorEltype(d)
end

@test reverse(PropertyDict((a=1, b=2, c=3))) === PropertyDict(reverse((a=1, b=2, c=3)))

push!(pd, :buz => 10)
@test pop!(pd, :buz) == 10
@test pop!(pd, :buz, 20) == 20
Expand Down

0 comments on commit e6f5797

Please sign in to comment.