Skip to content

Commit

Permalink
Fix delete! for WeakKeyDict to return the right object (JuliaLang#34203)
Browse files Browse the repository at this point in the history
  • Loading branch information
twavv authored and JeffBezanson committed Dec 30, 2019
1 parent 032dbe3 commit e03b730
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Standard library changes

* `methods` now accepts passing a module (or a list thereof) to filter methods defined in it ([#33403]).

* `delete!` on `WeakKeyDict`s now returns the `WeakKeyDict` itself instead of the underlying `Dict` used for implementation

#### Libdl

#### LinearAlgebra
Expand Down
2 changes: 1 addition & 1 deletion base/weakkeydict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function get!(default::Callable, wkh::WeakKeyDict{K}, key) where {K}
end
pop!(wkh::WeakKeyDict{K}, key) where {K} = lock(() -> pop!(wkh.ht, key), wkh)
pop!(wkh::WeakKeyDict{K}, key, default) where {K} = lock(() -> pop!(wkh.ht, key, default), wkh)
delete!(wkh::WeakKeyDict, key) = lock(() -> delete!(wkh.ht, key), wkh)
delete!(wkh::WeakKeyDict, key) = (lock(() -> delete!(wkh.ht, key), wkh); wkh)
empty!(wkh::WeakKeyDict) = (lock(() -> empty!(wkh.ht), wkh); wkh)
haskey(wkh::WeakKeyDict{K}, key) where {K} = lock(() -> haskey(wkh.ht, key), wkh)
getindex(wkh::WeakKeyDict{K}, key) where {K} = lock(() -> getindex(wkh.ht, key), wkh)
Expand Down
1 change: 1 addition & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ Dict(1 => rand(2,3), 'c' => "asdf") # just make sure this does not trigger a dep

wkd = WeakKeyDict(A=>1)
@test delete!(wkd, A) == empty(wkd)
@test delete!(wkd, A) === wkd

# issue #26939
d26939 = WeakKeyDict()
Expand Down

0 comments on commit e03b730

Please sign in to comment.