Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename haskey to hasindex #25105

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

const secret_table_token = :__c782dbf1cf4d6a2e5e3865d7e95634f2e09b5902__

haskey(d::AbstractDict, k) = in(k, keys(d))
hasindex(d::AbstractDict, k) = in(k, keys(d))

function in(p::Pair, a::AbstractDict, valcmp=(==))
v = get(a,p[1],secret_table_token)
Expand Down Expand Up @@ -224,7 +224,7 @@ Dict{Int64,Int64} with 3 entries:
function merge!(combine::Function, d::AbstractDict, others::AbstractDict...)
for other in others
for (k,v) in other
d[k] = haskey(d, k) ? combine(d[k], v) : v
d[k] = hasindex(d, k) ? combine(d[k], v) : v
end
end
return d
Expand Down
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ print_array(io::IO, X::AbstractArray) = show_nd(io, X, print_matrix, true)
# implements: show(io::IO, ::MIME"text/plain", X::AbstractArray)
function _display(io::IO, X::AbstractArray)
# 0) compute new IOContext
if !haskey(io, :compact) && length(axes(X, 2)) > 1
if !hasindex(io, :compact) && length(axes(X, 2)) > 1
io = IOContext(io, :compact => true)
end
if get(io, :limit, false) && eltype(X) === Method
Expand Down
4 changes: 2 additions & 2 deletions base/asyncmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ function next(itr::AsyncGenerator, state::AsyncGeneratorState)
state.i += 1

results_dict = itr.collector.results
while !haskey(results_dict, state.i)
while !hasindex(results_dict, state.i)
if done(itr.collector, state.collector_state)
# `done` waits for async tasks to finish. if we do not have the index
# we are looking for, it is an error.
!haskey(results_dict, state.i) && error("Error processing index ", i)
!hasindex(results_dict, state.i) && error("Error processing index ", i)
break;
end
_, state.collector_state = next(itr.collector, state.collector_state)
Expand Down
2 changes: 1 addition & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const exprresolve_cond_dict = Dict{Symbol,Function}(:(==) => ==,
:(<) => <, :(>) => >, :(<=) => <=, :(>=) => >=)

function exprresolve_arith(ex::Expr)
if ex.head == :call && haskey(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
if ex.head == :call && hasindex(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
return true, exprresolve_arith_dict[ex.args[1]](ex.args[2:end]...)
end
false, 0
Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function repl_color(key, default)
env_str = get(ENV, key, "")
c = tryparse(Int, env_str)
c_conv = isnull(c) ? Symbol(env_str) : get(c)
haskey(text_colors, c_conv) ? c_conv : default
hasindex(text_colors, c_conv) ? c_conv : default
end

error_color() = repl_color("JULIA_ERROR_COLOR", default_color_error)
Expand All @@ -103,7 +103,7 @@ function repl_cmd(cmd, out)
elseif length(cmd.exec) == 2
dir = cmd.exec[2]
if dir == "-"
if !haskey(ENV, "OLDPWD")
if !hasindex(ENV, "OLDPWD")
error("cd: OLDPWD not set")
end
cd(ENV["OLDPWD"])
Expand Down
10 changes: 5 additions & 5 deletions base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ deepcopy_internal(x::Tuple, stackdict::ObjectIdDict) =
deepcopy_internal(x::Module, stackdict::ObjectIdDict) = error("deepcopy of Modules not supported")

function deepcopy_internal(x::SimpleVector, stackdict::ObjectIdDict)
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]
end
y = Core.svec(Any[deepcopy_internal(x[i], stackdict) for i = 1:length(x)]...)
Expand All @@ -43,7 +43,7 @@ function deepcopy_internal(x::SimpleVector, stackdict::ObjectIdDict)
end

function deepcopy_internal(x::String, stackdict::ObjectIdDict)
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]
end
y = @gc_preserve x unsafe_string(pointer(x), sizeof(x))
Expand All @@ -55,7 +55,7 @@ function deepcopy_internal(@nospecialize(x), stackdict::ObjectIdDict)
T = typeof(x)::DataType
nf = nfields(x)
(isbits(T) || nf == 0) && return x
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]
end
y = ccall(:jl_new_struct_uninit, Any, (Any,), T)
Expand All @@ -72,7 +72,7 @@ function deepcopy_internal(@nospecialize(x), stackdict::ObjectIdDict)
end

function deepcopy_internal(x::Array, stackdict::ObjectIdDict)
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]
end
_deepcopy_array_t(x, eltype(x), stackdict)
Expand All @@ -97,7 +97,7 @@ function _deepcopy_array_t(@nospecialize(x), T, stackdict::ObjectIdDict)
end

function deepcopy_internal(x::Dict, stackdict::ObjectIdDict)
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]::typeof(x)
end

Expand Down
5 changes: 4 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const _oldstyle_array_vcat_ = false

function delete!(::EnvDict, k::AbstractString, def)
depwarn("`delete!(ENV, k, def)` should be replaced with `pop!(ENV, k, def)`. Be aware that `pop!` returns `k` or `def`, while `delete!` returns `ENV` or `def`.", :delete!)
haskey(ENV,k) ? delete!(ENV,k) : def
hasindex(ENV,k) ? delete!(ENV,k) : def
end

# Deprecate methods that convert Diagonal and Bidiagonal to <:AbstractTriangular.
Expand Down Expand Up @@ -3248,6 +3248,9 @@ end
@deprecate indices(a) axes(a)
@deprecate indices(a, d) axes(a, d)

# PR #??
@deprecate haskey(a, i) hasindex(a, i)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
14 changes: 7 additions & 7 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
function show(io::IO, t::AbstractDict{K,V}) where V where K
recur_io = IOContext(io, :SHOWN_SET => t)
limit::Bool = get(io, :limit, false)
if !haskey(io, :compact)
if !hasindex(io, :compact)
recur_io = IOContext(recur_io, :compact => true)
end

Expand Down Expand Up @@ -195,7 +195,7 @@ function convert(::Type{Dict{K,V}},d::AbstractDict) where V where K
h = Dict{K,V}()
for (k,v) in d
ck = convert(K,k)
if !haskey(h,ck)
if !hasindex(h,ck)
h[ck] = convert(V,v)
else
error("key collision during dictionary conversion")
Expand Down Expand Up @@ -568,7 +568,7 @@ function get(default::Callable, h::Dict{K,V}, key) where V where K
end

"""
haskey(collection, key) -> Bool
hasindex(collection, key) -> Bool

Determine whether a collection has a mapping for a given key.

Expand All @@ -578,14 +578,14 @@ Dict{Char,Int64} with 2 entries:
'b' => 3
'a' => 2

julia> haskey(a,'a')
julia> hasindex(a,'a')
true

julia> haskey(a,'c')
julia> hasindex(a,'c')
false
```
"""
haskey(h::Dict, key) = (ht_keyindex(h, key) >= 0)
hasindex(h::Dict, key) = (ht_keyindex(h, key) >= 0)
in(key, v::KeySet{<:Any, <:Dict}) = (ht_keyindex(v.dict, key) >= 0)

"""
Expand Down Expand Up @@ -767,7 +767,7 @@ function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
return false
end

function haskey(dict::ImmutableDict, key)
function hasindex(dict::ImmutableDict, key)
while isdefined(dict, :parent)
dict.key == key && return true
dict = dict.parent
Expand Down
16 changes: 8 additions & 8 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ end
function docstr(binding::Binding, @nospecialize typesig = Union{})
for m in modules
dict = meta(m)
if haskey(dict, binding)
if hasindex(dict, binding)
docs = dict[binding].docs
if haskey(docs, typesig)
if hasindex(docs, typesig)
return docs[typesig]
end
end
Expand Down Expand Up @@ -232,7 +232,7 @@ Adds a new docstring `str` to the docsystem of `__module__` for `binding` and si
function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize sig = Union{})
initmeta(__module__)
m = get!(meta(__module__), b, MultiDoc())
if haskey(m.docs, sig)
if hasindex(m.docs, sig)
# We allow for docstrings to be updated, but print a warning since it is possible
# that over-writing a docstring *may* have been accidental. The warning
# is suppressed for symbols in Main, for interactive use (#23011).
Expand Down Expand Up @@ -287,7 +287,7 @@ function doc(binding::Binding, sig::Type = Union{})
# Lookup `binding` and `sig` for matches in all modules of the docsystem.
for mod in modules
dict = meta(mod)
if haskey(dict, binding)
if hasindex(dict, binding)
multidoc = dict[binding]
push!(groups, multidoc)
for msig in multidoc.order
Expand Down Expand Up @@ -335,11 +335,11 @@ Return documentation for a particular `field` of a type if it exists.
function fielddoc(binding::Binding, field::Symbol)
for mod in modules
dict = meta(mod)
if haskey(dict, binding)
if hasindex(dict, binding)
multidoc = dict[binding]
if haskey(multidoc.docs, Union{})
if hasindex(multidoc.docs, Union{})
fields = multidoc.docs[Union{}].data[:fields]
if haskey(fields, field)
if hasindex(fields, field)
doc = fields[field]
return isa(doc, Markdown.MD) ? doc : Markdown.parse(doc)
end
Expand Down Expand Up @@ -730,7 +730,7 @@ end
function docm(source::LineNumberNode, mod::Module, ex)
if isexpr(ex, :->)
docm(source, mod, ex.args...)
elseif haskey(keywords, ex)
elseif hasindex(keywords, ex)
parsedoc(keywords[ex])
elseif isa(ex, Union{Expr, Symbol})
binding = esc(bindingexpr(namify(ex)))
Expand Down
10 changes: 5 additions & 5 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end
function helpmode(io::IO, line::AbstractString)
line = strip(line)
expr =
if haskey(keywords, Symbol(line))
if hasindex(keywords, Symbol(line))
# Docs for keywords must be treated separately since trying to parse a single
# keyword such as `function` would throw a parse error due to the missing `end`.
Symbol(line)
Expand Down Expand Up @@ -158,7 +158,7 @@ function repl_latex(io::IO, s::String)
print(io, latex, "<tab>")
end
println(io, '\n')
elseif any(c -> haskey(symbols_latex, string(c)), s)
elseif any(c -> hasindex(symbols_latex, string(c)), s)
print(io, "\"")
Markdown.with_output_format(:cyan, io) do io
print(io, s)
Expand All @@ -167,7 +167,7 @@ function repl_latex(io::IO, s::String)
Markdown.with_output_format(:cyan, io) do io
for c in s
cstr = string(c)
if haskey(symbols_latex, cstr)
if hasindex(symbols_latex, cstr)
print(io, symbols_latex[cstr], "<tab>")
else
print(io, c)
Expand All @@ -187,7 +187,7 @@ function repl(io::IO, s::Symbol)
quote
repl_latex($io, $str)
repl_search($io, $str)
$(if !isdefined(Main, s) && !haskey(keywords, s)
$(if !isdefined(Main, s) && !hasindex(keywords, s)
:(repl_corrections($io, $str))
end)
$(_repl(s))
Expand Down Expand Up @@ -399,7 +399,7 @@ end

function docsearch(haystack::DocStr, needle)
docsearch(parsedoc(haystack), needle) && return true
if haskey(haystack.data, :fields)
if hasindex(haystack.data, :fields)
for doc in values(haystack.data[:fields])
docsearch(doc, needle) && return true
end
Expand Down
2 changes: 1 addition & 1 deletion base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ get(::EnvDict, k::AbstractString, def) = access_env(k->def, k)
get(f::Callable, ::EnvDict, k::AbstractString) = access_env(k->f(), k)
in(k::AbstractString, ::KeySet{String, EnvDict}) = _hasenv(k)
pop!(::EnvDict, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v)
pop!(::EnvDict, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def
pop!(::EnvDict, k::AbstractString, def) = hasindex(ENV,k) ? pop!(ENV,k) : def
delete!(::EnvDict, k::AbstractString) = (_unsetenv(k); ENV)
setindex!(::EnvDict, v, k::AbstractString) = _setenv(k,string(v))
push!(::EnvDict, k::AbstractString, v) = setindex!(ENV, v, k)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ export
get!,
getindex,
getkey,
haskey,
hasindex,
in,
intersect!,
intersect,
Expand Down
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ Base.sub_with_overflow(a::BigInt, b::BigInt) = a - b, false
Base.mul_with_overflow(a::BigInt, b::BigInt) = a * b, false

function Base.deepcopy_internal(x::BigInt, stackdict::ObjectIdDict)
if haskey(stackdict, x)
if hasindex(stackdict, x)
return stackdict[x]
end
y = MPZ.set(x)
Expand Down
Loading