-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add IsIterable trait #25
Conversation
src/base-traits.jl
Outdated
@@ -57,4 +61,11 @@ end | |||
|
|||
Base.@deprecate_binding IsFastLinearIndex IsIndexLinear | |||
|
|||
@static if VERSION >= v"0.6.0-dev" | |||
@traitdef IsIterable{X} |
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.
Add a tiny doc string.
src/base-traits.jl
Outdated
@@ -6,6 +6,10 @@ using Compat | |||
export IsLeafType, IsBits, IsImmutable, IsContiguous, IsIndexLinear, | |||
IsAnything, IsNothing, IsCallable | |||
|
|||
@static if VERSION >= v"0.6.0-dev" |
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.
Have you checked that this does not work in 0.5?
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.
Ha, I didn't, but it seems to work on 0.5 as well!
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.
BTW: My comment above about the new type system was related to a "complete" solution to this type of interface specification, as it is done in Traits.jl.
test/base-traits.jl
Outdated
|
||
if VERSION >= v"0.6.0-dev" | ||
@test istrait(IsIterable{Array}) | ||
@test !istrait(IsIterable{Cmd}) |
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.
Let's add those two tests for good measure:
julia> method_exists(start, Tuple{Base.UnitRange{Int}})
true
julia> method_exists(start, Tuple{Base.UnitRange})
true
(I remember that parameterized methods sometimes tripped up method_exists
. So in case there is a regression.)
Thanks for your PR! |
Alright, I think I addressed all your requests. |
test/base-traits.jl
Outdated
@test istrait(IsIterable{Array}) | ||
@test !istrait(IsIterable{Cmd}) | ||
@test method_exists(start, Tuple{Base.UnitRange{Int}}) | ||
@test method_exists(start, Tuple{Base.UnitRange}) |
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.
Sorry, I wasn't clear at all, I meant:
@test istrait(IsIterable{Base.UnitRange{Int}})
@test istrait(IsIterable{Base.LogicalIndex})
and not testing the method_exists directly.
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.
Other than that, LGTM.
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 second one should also test UnitRange
, not LogicalIndex
, right?
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.
Yes. Just trying to confuse you more ;-)
Thanks for the contribution! |
I'm a bit stomped by this test failure as it didn't show up in the CI of PR: #34 Furthermore, the same issue existed as far back as #25 I tried to see whether this was introduced in one of the minor versions of Julia 0.5. But running the test now locally fails for all 0.5.0, 0.5.1 and 0.5.2. So, not sure what changed.
I'm a bit stomped by this test failure as it didn't show up in the CI of PR: #34 Furthermore, the same issue existed as far back as #25 I tried to see whether this was introduced in one of the minor versions of Julia 0.5. But running the test now locally fails for all 0.5.0, 0.5.1 and 0.5.2. So, not sure what changed.
Right now I'm only checking whether a
start
method is defined. I guess I could also check fornext
anddone
, but in some way I feel this should be enough.