-
-
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
return pairs instead of tuples when iterating Associatives #12327
Conversation
function in(p::Tuple{Any,Any}, a::Associative) | ||
function in(p, a::Associative) | ||
if !isa(p,Pair) | ||
error("Associative collections only contain Pairs; look for e.g. A=>B 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.
Would it be cleaner to use dispatch here?
Should this be a TypeError?
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.
The descriptive error message seems fine to me, though I'd like it to also point people to keys
and values
function, since I think if people are in this situation they are most likely looking for one or the other.
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.
We could use dispatch, but there is a fallback definition of in
for all types that will unhelpfully just return false
in this case. This isn't really a type error, since it's perfectly valid to ask whether some random thing is in a collection. This is kind of a "fuzzy" error just meant to be helpful.
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.
@Keno yes good idea.
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.
@JeffBezanson I thought that function in(p, a::Associative)
and function in(p::Pair, a::Associative)
would fallback correctly/equivalently? (or specific error for function in(p::Tuple{Any,Any}, a::Associative)
).
+1 to directing towards A in keys(a)
and B in values(a)
Also note that before this change |
@JeffBezanson @tkelman Seems like that makes parts of this PR eligible for backport to the |
release-0.3 would need a different fix; it doesn't have Pairs. |
Yes, definitely. Tuples (not Pair) for 0.3 |
return pairs instead of tuples when iterating Associatives
We should probably have test for the |
Yes. |
If no one has tried to |
- Fix some more 0.4 deprecations - Add support for emoji_symbols - Handle characters that do not have assigned Unicode names
fixes #12261