Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Apr 15, 2025

Neither Nothing or Missing are iterators, iterate(nothing) throws: thus eltype should throw for such arguments as well.

Neither `Nothing` or `Missing` are iterators, `iterate(nothing)`
throws: thus `eltype` should throw for such arguments as well.
@nsajko nsajko added missing data Base.missing and related functionality iteration Involves iteration or the iteration protocol needs pkgeval Tests for all registered packages should be run with this change labels Apr 15, 2025
Copy link
Member

@vtjnash vtjnash left a 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

@vtjnash
Copy link
Member

vtjnash commented Apr 15, 2025

The PR also breaks a handful of tests, so it is probably not worth considering

@nsajko
Copy link
Contributor Author

nsajko commented Apr 15, 2025

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

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.

The PR also breaks a handful of tests, so it is probably not worth considering

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 @test_throws test that check for a hardcoded error message.

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 missing data Base.missing and related functionality needs pkgeval Tests for all registered packages should be run with this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants