-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
make eltype
throw for some known noniterators
#58122
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
Conversation
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.
I don't believe there is anything about not implementing iteration or getindex which implies that eltype needs to throw or return anything particularly special
The PR also breaks a handful of tests, so it is probably not worth considering |
It's better to throw than to return an incorrect result silently. Any possible return value is incorrect, given that a non-iterator doesn't have an element type. Thus throwing seems to be left as the only option.
I haven't yet looked through all or even most of these, but I'm not disheartened by what I've seen yet. Some of the test failures are benign things, such as |
I'm not sure that's true in general: surely there are examples in the ecosystem of containers that don't implement iteration but have a meaningful notion of element(s) and thus element type. There's also nothing special about
I'm somewhat ambivalent about how I haven't looked at the failing tests but this feels like it has the potential to be more breaking than it appears. FWIW, the generic fallback for |
Neither `Nothing` or `Missing` are iterators, `iterate(nothing)` throws: thus `eltype` should throw for such arguments as well.
a970a01
to
ca285fe
Compare
I agree, now that you pointed it out, given the special, missing data, semantics of
In that case I guess such a "container" would better use some other function instead of |
Can a function not be part of two interfaces? |
Eh, |
Neither
Nothing
orMissing
are iterators,iterate(nothing)
throws: thuseltype
should throw for such arguments as well.