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

Audit iterator traits to make sure they're always called on types #25733

Merged
merged 1 commit into from
Jan 25, 2018

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 24, 2018

The iterator wrappers assume that eltype is called on the type of
the wrapped iterator, not the value itself, so all objects that
implement these traits need to do so. Audit all of them in base
and make sure that's the case.

@@ -748,7 +748,7 @@ function IteratorEltype(::Type{ProductIterator{T}}) where {T<:Tuple}
IteratorEltype(I) == EltypeUnknown() ? EltypeUnknown() : IteratorEltype(P)
end

eltype(P::ProductIterator) = _prod_eltype(P.iterators)
eltype(::Type{<:ProductIterator{I}}) where {I} = _prod_eltype((I.parameters...,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally these should be rewritten to use tuple_type_head.

@@ -35,7 +35,7 @@ end

parent(a::ReinterpretArray) = a.parent

eltype(a::ReinterpretArray{T}) where {T} = T
eltype(a::Type{<:ReinterpretArray{T}}) where {T} = T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary; should be inherited from AbstractArray.

@@ -1456,6 +1456,7 @@ for (G, A) in ((GenericSet, AbstractSet),
Base.$f(s::$G) = $f(s.s)
end
end
Base.eltype(::Type{<:G}) = eltype(fieldtype(G, :s))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also covered by AbstractSet I think.

@Keno Keno added the iteration Involves iteration or the iteration protocol label Jan 24, 2018
@ararslan ararslan added the traits Traits, sometimes called Tim Holy Traits label Jan 25, 2018
The iterator wrappers assume that eltype is called on the type of
the wrapped iterator, not the value itself, so all objects that
implement these traits need to do so. Audit all of them in base
and make sure that's the case.
@mschauer
Copy link
Contributor

This forgot to update the docstring

help?> Base.IteratorSize
  IteratorSize(itertype::Type) -> IteratorSize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iteration Involves iteration or the iteration protocol traits Traits, sometimes called Tim Holy Traits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants