-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
RFC: eliminate getindex(::Number) #19700
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
|
OTOH all of the related hard to debug issues I've had are caused by numbers being iterable though..... (they are basically all |
|
Even if we do eventually want to make numbers non-iterable (which I'm more skeptical of now that I see how much inconvenience it will cause in Base), removing |
|
shouldn't it be deprecated first, rather than immediately removed? |
|
@tkelman, right, I need to add deprecations and NEWS, but I wanted to check first whether we even want to do this. |
0d1fa22 to
b20efad
Compare
|
Added deprecations and NEWS. |
|
@StefanKarpinski, do you have an opinion on this? |
1f9d3de to
2e8ed38
Compare
|
Rebased; bump. |
|
(Removing the breaking label since there is deprecation code.) |
|
Why not leave |
|
@iamed2, if we leave that we should leave the rest, and not merge this. Which is fine with me; I don't have strong feelings about whether numbers should act as 0-dimensional arrays. |
|
The consensus on the triage call was leaning against this. I feel it's better to support all or none of the 0-d array interface, and, as has been observed, iteration tends to cause more problems here than indexing. |
|
I discovered
I find special treatment for numbers only confusing. I think that (1) would have ramifications that are surprising. |
|
I think that argument is a bit too pedantic. "Always" and "never" aren't the only two reasonable options; in fact we tend to prefer "as needed". There is precedent for considering scalars to be "0-dimensional", and in practice we've wanted that behavior in many cases. As far as I know there has not been much need to extend this to other kinds of objects. Of course your option (2) is popular, but trying to implement it has proven frustrating so far. I think there is still a chance we will eventually make this change though. In any case this PR doesn't do that, so I'll close it. |
This PR partially addresses #7903: it makes numbers non-indexable, so that they no longer act like 0-dimensional arrays (no
size,getindex,ndims, etc). (broadcastis unaffected.)Pro: being able to do
1[1]was always a bit odd, and it doesn't seem to gain us much. Eliminating this functionality seems to require minimal changes to Base. Also, thef.(x)syntax removes some of the impetus to write functions where scalars can be treated like arrays.Con: eliminating this functionality doesn't actually save us much code in Base, and it might make some kinds of generic functions more annoying to write, especially since numbers are still iterable. Is it worth it?
I initially also tried making numbers non-iterable (removing
startetc.). However, I quickly found that there is a lot of code in Base that is affected, and would seem to become much uglier without this capability (see #7903 (comment)). My conclusion is that making numbers iterable is more likely something we want to retain.