-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
in
uses isequal
(#9381)
#24563
in
uses isequal
(#9381)
#24563
Conversation
There are quite a few more methods of |
Thanks for pointing that out, I was just about to ask about that. For example, in associative.jl function in(p::Pair, a::Associative, valcmp=(==))
v = get(a,p[1],secret_table_token)
if v !== secret_table_token
valcmp(v, p[2]) && return true
end
return false
end Do you want in(x::Char, y::Char) = x == y goes to in(x::Char, y::Char) = isequal(x, y) change anything? When I look into this more, there are definitely a few that I need to change e.g. |
Yes, I would change all of these. In some cases |
NEWS.md
Outdated
@@ -272,6 +272,8 @@ This section lists changes that do not have deprecation warnings. | |||
Library improvements | |||
-------------------- | |||
|
|||
* `in` now uses `isequal` to test for containment ([#9381]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be listed under breaking changes instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, fixed.
I also wonder if |
Is that idea relevant to this PR? I don't think that it is inconsistent to have |
Not in the sense that this PR needs modifying. :) However, I think there is a fair amount of relevance to #9381 (actually I should have probably put my comment there instead, sorry!) in that I would say that containers would be equal when they contain (i.e. |
base/associative.jl
Outdated
@@ -67,7 +67,7 @@ function next(v::ValueIterator, state) | |||
n[1][2], n[2] | |||
end | |||
|
|||
in(k, v::KeyIterator) = get(v.dict, k, secret_table_token) !== secret_table_token | |||
in(k, v::KeyIterator) = !isequal(get(v.dict, k, secret_table_token), secret_table_token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not quite right. This is using !==
(which is the opposite of ===
, not ==
) to see if exactly the secret_table_token
object was returned.
base/env.jl
Outdated
@@ -4,7 +4,7 @@ if Sys.iswindows() | |||
const ERROR_ENVVAR_NOT_FOUND = UInt32(203) | |||
|
|||
_getenvlen(var::Vector{UInt16}) = ccall(:GetEnvironmentVariableW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32),var,C_NULL,0) | |||
_hasenv(s::Vector{UInt16}) = _getenvlen(s) != 0 || Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND | |||
_hasenv(s::Vector{UInt16}) = !isequal(_getenvlen(s), 0) || !isequal(Libc.GetLastError(), ERROR_ENVVAR_NOT_FOUND) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't need to change.
base/env.jl
Outdated
@@ -38,7 +38,7 @@ if Sys.iswindows() | |||
end | |||
else # !windows | |||
_getenv(var::AbstractString) = ccall(:getenv, Cstring, (Cstring,), var) | |||
_hasenv(s::AbstractString) = _getenv(s) != C_NULL | |||
_hasenv(s::AbstractString) = !isequal(_getenv(s), C_NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this.
base/show.jl
Outdated
@@ -87,7 +87,7 @@ pipe_writer(io::IOContext) = io.io | |||
lock(io::IOContext) = lock(io.io) | |||
unlock(io::IOContext) = unlock(io.io) | |||
|
|||
in(key_value::Pair, io::IOContext) = in(key_value, io.dict, ===) | |||
in(key_value::Pair, io::IOContext) = in(key_value, io.dict, isequal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not change since the caller was specifically requesting ===
.
base/strings/search.jl
Outdated
@@ -44,7 +44,7 @@ function search(s::AbstractString, c::Chars, i::Integer) | |||
end | |||
search(s::AbstractString, c::Chars) = search(s,c,start(s)) | |||
|
|||
in(c::Char, s::AbstractString) = (search(s,c)!=0) | |||
in(c::Char, s::AbstractString) = !isequal(search(s,c), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also not change, since it isn't comparing c
; it's testing the result of a different function.
Thanks @JeffBezanson , I may have gone a bit overboard with some of those changes. I have changed back to the old style in all of the places that you asked. |
Closing due to comment in #9381 |
Thank you regardless for your efforts here, @JackDevine! |
I changed the docstring quite a bit, I think that it is now a good description of the current behavior. I also added the test in the first comment of #9381.
Edit: fix #9381