Skip to content

Commit 067372b

Browse files
adienesclaude
andauthored
Fix Base.hash to use only the two-arg method (#602)
Generated as part of an ecosystem-wide audit for one-arg hash methods. `Base.hash` should only be extended via the two-arg method `hash(x, h::UInt)`. Defining a one-arg `hash(x)` method, or giving the second argument a default value, can lead to correctness bugs (hash contract violations when the seed differs from the hard-coded default) and invalidation-related performance issues. This is particularly necessary for Julia 1.13+ where the default hash seed value will change. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3c658d8 commit 067372b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/PyPlot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ convert(::Type{Figure}, o::PyObject) = Figure(o)
7373
==(f::Figure, g::Figure) = PyObject(f) == PyObject(g)
7474
==(f::Figure, g::PyObject) = PyObject(f) == g
7575
==(f::PyObject, g::Figure) = f == PyObject(g)
76-
hash(f::Figure) = hash(PyObject(f))
76+
hash(f::Figure, h::UInt) = hash(PyObject(f), h)
7777
pycall(f::Figure, args...; kws...) = pycall(PyObject(f), args...; kws...)
7878
(f::Figure)(args...; kws...) = pycall(PyObject(f), PyAny, args...; kws...)
7979
Base.Docs.doc(f::Figure) = Base.Docs.doc(PyObject(f))

src/colormaps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ convert(::Type{ColorMap}, o::PyObject) = ColorMap(o)
1616
==(c::ColorMap, g::ColorMap) = PyObject(c) == PyObject(g)
1717
==(c::PyObject, g::ColorMap) = c == PyObject(g)
1818
==(c::ColorMap, g::PyObject) = PyObject(c) == g
19-
hash(c::ColorMap) = hash(PyObject(c))
19+
hash(c::ColorMap, h::UInt) = hash(PyObject(c), h)
2020
pycall(c::ColorMap, args...; kws...) = pycall(PyObject(c), args...; kws...)
2121
(c::ColorMap)(args...; kws...) = pycall(PyObject(c), PyAny, args...; kws...)
2222
Base.Docs.doc(c::ColorMap) = Base.Docs.doc(PyObject(c))

0 commit comments

Comments
 (0)